blob: ebb55435729b75a5a555007cf04fe354549392c0 [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 }
Joe Topjiand131fb82017-01-11 21:41:44 -070073 defer DeleteProject(t, client, project.ID)
Joe Topjian8ad602c2017-01-11 21:01:47 -070074
75 PrintProject(t, project)
Joe Topjian8baf47a2017-01-11 21:50:24 -070076
77 var iFalse bool = false
78 updateOpts := projects.UpdateOpts{
79 Enabled: &iFalse,
80 }
81
82 updatedProject, err := projects.Update(client, project.ID, updateOpts).Extract()
83 if err != nil {
84 t.Fatalf("Unable to update project: %v", err)
85 }
86
87 PrintProject(t, updatedProject)
Joe Topjian8ad602c2017-01-11 21:01:47 -070088}
89
90func TestProjectsDomain(t *testing.T) {
91 client, err := clients.NewIdentityV3Client()
92 if err != nil {
93 t.Fatalf("Unable to obtain an identity client: %v")
94 }
95
96 var iTrue = true
97 createOpts := projects.CreateOpts{
98 IsDomain: &iTrue,
99 }
100
101 projectDomain, err := CreateProject(t, client, &createOpts)
102 if err != nil {
103 t.Fatalf("Unable to create project: %v", err)
104 }
Joe Topjian8baf47a2017-01-11 21:50:24 -0700105 defer DeleteProject(t, client, projectDomain.ID)
Joe Topjian8ad602c2017-01-11 21:01:47 -0700106
107 PrintProject(t, projectDomain)
108
109 createOpts = projects.CreateOpts{
110 DomainID: projectDomain.ID,
111 }
112
113 project, err := CreateProject(t, client, &createOpts)
114 if err != nil {
115 t.Fatalf("Unable to create project: %v", err)
116 }
Joe Topjian8baf47a2017-01-11 21:50:24 -0700117 defer DeleteProject(t, client, project.ID)
Joe Topjian8ad602c2017-01-11 21:01:47 -0700118
119 PrintProject(t, project)
Joe Topjian8baf47a2017-01-11 21:50:24 -0700120
121 var iFalse = false
122 updateOpts := projects.UpdateOpts{
123 Enabled: &iFalse,
124 }
125
126 _, err = projects.Update(client, projectDomain.ID, updateOpts).Extract()
127 if err != nil {
128 t.Fatalf("Unable to disable domain: %v")
129 }
Joe Topjian8ad602c2017-01-11 21:01:47 -0700130}
131
132func TestProjectsNested(t *testing.T) {
133 client, err := clients.NewIdentityV3Client()
134 if err != nil {
135 t.Fatalf("Unable to obtain an identity client: %v")
136 }
137
138 projectMain, err := CreateProject(t, client, nil)
139 if err != nil {
140 t.Fatalf("Unable to create project: %v", err)
141 }
Joe Topjian8baf47a2017-01-11 21:50:24 -0700142 defer DeleteProject(t, client, projectMain.ID)
Joe Topjian8ad602c2017-01-11 21:01:47 -0700143
144 PrintProject(t, projectMain)
145
146 createOpts := projects.CreateOpts{
147 ParentID: projectMain.ID,
148 }
149
150 project, err := CreateProject(t, client, &createOpts)
151 if err != nil {
152 t.Fatalf("Unable to create project: %v", err)
153 }
Joe Topjian8baf47a2017-01-11 21:50:24 -0700154 defer DeleteProject(t, client, project.ID)
Joe Topjian8ad602c2017-01-11 21:01:47 -0700155
156 PrintProject(t, project)
157}