blob: 4b2e53970aef72178ca78e82611e74d0067de76a [file] [log] [blame]
Joe Topjianf61691c2016-11-05 12:34:59 -06001// +build acceptance
2
3package v3
4
5import (
6 "testing"
7
8 "github.com/gophercloud/gophercloud/acceptance/clients"
9 "github.com/gophercloud/gophercloud/openstack/identity/v3/projects"
10)
11
12func TestProjectsList(t *testing.T) {
13 client, err := clients.NewIdentityV3Client()
14 if err != nil {
Joe Topjian1c236d32017-01-09 15:33:32 -070015 t.Fatalf("Unable to obtain an identity client: %v", err)
Joe Topjianf61691c2016-11-05 12:34:59 -060016 }
17
18 var iTrue bool = true
19 listOpts := projects.ListOpts{
20 Enabled: &iTrue,
21 }
22
23 allPages, err := projects.List(client, listOpts).AllPages()
24 if err != nil {
25 t.Fatalf("Unable to list projects: %v", err)
26 }
27
28 allProjects, err := projects.ExtractProjects(allPages)
29 if err != nil {
30 t.Fatalf("Unable to extract projects: %v", err)
31 }
32
33 for _, project := range allProjects {
34 PrintProject(t, &project)
35 }
36}
Joe Topjian1c236d32017-01-09 15:33:32 -070037
38func TestProjectsGet(t *testing.T) {
39 client, err := clients.NewIdentityV3Client()
40 if err != nil {
41 t.Fatalf("Unable to obtain an identity client: %v", err)
42 }
43
44 allPages, err := projects.List(client, nil).AllPages()
45 if err != nil {
46 t.Fatalf("Unable to list projects: %v", err)
47 }
48
49 allProjects, err := projects.ExtractProjects(allPages)
50 if err != nil {
51 t.Fatalf("Unable to extract projects: %v", err)
52 }
53
54 project := allProjects[0]
55 p, err := projects.Get(client, project.ID, nil).Extract()
56 if err != nil {
57 t.Fatalf("Unable to get project: %v", err)
58 }
59
60 PrintProject(t, p)
61}
Joe Topjian8ad602c2017-01-11 21:01:47 -070062
63func TestProjectsCRUD(t *testing.T) {
64 client, err := clients.NewIdentityV3Client()
65 if err != nil {
66 t.Fatalf("Unable to obtain an identity client: %v")
67 }
68
69 project, err := CreateProject(t, client, nil)
70 if err != nil {
71 t.Fatalf("Unable to create project: %v", err)
72 }
73
74 PrintProject(t, project)
75}
76
77func TestProjectsDomain(t *testing.T) {
78 client, err := clients.NewIdentityV3Client()
79 if err != nil {
80 t.Fatalf("Unable to obtain an identity client: %v")
81 }
82
83 var iTrue = true
84 createOpts := projects.CreateOpts{
85 IsDomain: &iTrue,
86 }
87
88 projectDomain, err := CreateProject(t, client, &createOpts)
89 if err != nil {
90 t.Fatalf("Unable to create project: %v", err)
91 }
92
93 PrintProject(t, projectDomain)
94
95 createOpts = projects.CreateOpts{
96 DomainID: projectDomain.ID,
97 }
98
99 project, err := CreateProject(t, client, &createOpts)
100 if err != nil {
101 t.Fatalf("Unable to create project: %v", err)
102 }
103
104 PrintProject(t, project)
105}
106
107func TestProjectsNested(t *testing.T) {
108 client, err := clients.NewIdentityV3Client()
109 if err != nil {
110 t.Fatalf("Unable to obtain an identity client: %v")
111 }
112
113 projectMain, err := CreateProject(t, client, nil)
114 if err != nil {
115 t.Fatalf("Unable to create project: %v", err)
116 }
117
118 PrintProject(t, projectMain)
119
120 createOpts := projects.CreateOpts{
121 ParentID: projectMain.ID,
122 }
123
124 project, err := CreateProject(t, client, &createOpts)
125 if err != nil {
126 t.Fatalf("Unable to create project: %v", err)
127 }
128
129 PrintProject(t, project)
130}