blob: b82d72c6fc11a8ef2077f728e8bb4b1d753d0240 [file] [log] [blame]
Joe Topjianf61691c2016-11-05 12:34:59 -06001// +build acceptance
2
3package v3
4
5import (
6 "testing"
7
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02008 "gerrit.mcp.mirantis.net/debian/gophercloud.git/acceptance/clients"
9 "gerrit.mcp.mirantis.net/debian/gophercloud.git/acceptance/tools"
10 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/identity/v3/projects"
Joe Topjianf61691c2016-11-05 12:34:59 -060011)
12
13func TestProjectsList(t *testing.T) {
14 client, err := clients.NewIdentityV3Client()
15 if err != nil {
Joe Topjian1c236d32017-01-09 15:33:32 -070016 t.Fatalf("Unable to obtain an identity client: %v", err)
Joe Topjianf61691c2016-11-05 12:34:59 -060017 }
18
19 var iTrue bool = true
20 listOpts := projects.ListOpts{
21 Enabled: &iTrue,
22 }
23
24 allPages, err := projects.List(client, listOpts).AllPages()
25 if err != nil {
26 t.Fatalf("Unable to list projects: %v", err)
27 }
28
29 allProjects, err := projects.ExtractProjects(allPages)
30 if err != nil {
31 t.Fatalf("Unable to extract projects: %v", err)
32 }
33
34 for _, project := range allProjects {
Joe Topjian66a046c2017-01-19 22:07:26 -070035 tools.PrintResource(t, project)
Joe Topjianf61691c2016-11-05 12:34:59 -060036 }
37}
Joe Topjian1c236d32017-01-09 15:33:32 -070038
39func TestProjectsGet(t *testing.T) {
40 client, err := clients.NewIdentityV3Client()
41 if err != nil {
42 t.Fatalf("Unable to obtain an identity client: %v", err)
43 }
44
45 allPages, err := projects.List(client, nil).AllPages()
46 if err != nil {
47 t.Fatalf("Unable to list projects: %v", err)
48 }
49
50 allProjects, err := projects.ExtractProjects(allPages)
51 if err != nil {
52 t.Fatalf("Unable to extract projects: %v", err)
53 }
54
55 project := allProjects[0]
56 p, err := projects.Get(client, project.ID, nil).Extract()
57 if err != nil {
58 t.Fatalf("Unable to get project: %v", err)
59 }
60
Joe Topjian66a046c2017-01-19 22:07:26 -070061 tools.PrintResource(t, p)
Joe Topjian1c236d32017-01-09 15:33:32 -070062}
Joe Topjian8ad602c2017-01-11 21:01:47 -070063
64func TestProjectsCRUD(t *testing.T) {
65 client, err := clients.NewIdentityV3Client()
66 if err != nil {
67 t.Fatalf("Unable to obtain an identity client: %v")
68 }
69
70 project, err := CreateProject(t, client, nil)
71 if err != nil {
72 t.Fatalf("Unable to create project: %v", err)
73 }
Joe Topjiand131fb82017-01-11 21:41:44 -070074 defer DeleteProject(t, client, project.ID)
Joe Topjian8ad602c2017-01-11 21:01:47 -070075
Joe Topjian66a046c2017-01-19 22:07:26 -070076 tools.PrintResource(t, project)
Joe Topjian8baf47a2017-01-11 21:50:24 -070077
78 var iFalse bool = false
79 updateOpts := projects.UpdateOpts{
80 Enabled: &iFalse,
81 }
82
83 updatedProject, err := projects.Update(client, project.ID, updateOpts).Extract()
84 if err != nil {
85 t.Fatalf("Unable to update project: %v", err)
86 }
87
Joe Topjian66a046c2017-01-19 22:07:26 -070088 tools.PrintResource(t, updatedProject)
Joe Topjian8ad602c2017-01-11 21:01:47 -070089}
90
91func TestProjectsDomain(t *testing.T) {
92 client, err := clients.NewIdentityV3Client()
93 if err != nil {
94 t.Fatalf("Unable to obtain an identity client: %v")
95 }
96
97 var iTrue = true
98 createOpts := projects.CreateOpts{
99 IsDomain: &iTrue,
100 }
101
102 projectDomain, err := CreateProject(t, client, &createOpts)
103 if err != nil {
104 t.Fatalf("Unable to create project: %v", err)
105 }
Joe Topjian8baf47a2017-01-11 21:50:24 -0700106 defer DeleteProject(t, client, projectDomain.ID)
Joe Topjian8ad602c2017-01-11 21:01:47 -0700107
Joe Topjian66a046c2017-01-19 22:07:26 -0700108 tools.PrintResource(t, projectDomain)
Joe Topjian8ad602c2017-01-11 21:01:47 -0700109
110 createOpts = projects.CreateOpts{
111 DomainID: projectDomain.ID,
112 }
113
114 project, err := CreateProject(t, client, &createOpts)
115 if err != nil {
116 t.Fatalf("Unable to create project: %v", err)
117 }
Joe Topjian8baf47a2017-01-11 21:50:24 -0700118 defer DeleteProject(t, client, project.ID)
Joe Topjian8ad602c2017-01-11 21:01:47 -0700119
Joe Topjian66a046c2017-01-19 22:07:26 -0700120 tools.PrintResource(t, project)
Joe Topjian8baf47a2017-01-11 21:50:24 -0700121
122 var iFalse = false
123 updateOpts := projects.UpdateOpts{
124 Enabled: &iFalse,
125 }
126
127 _, err = projects.Update(client, projectDomain.ID, updateOpts).Extract()
128 if err != nil {
129 t.Fatalf("Unable to disable domain: %v")
130 }
Joe Topjian8ad602c2017-01-11 21:01:47 -0700131}
132
133func TestProjectsNested(t *testing.T) {
134 client, err := clients.NewIdentityV3Client()
135 if err != nil {
136 t.Fatalf("Unable to obtain an identity client: %v")
137 }
138
139 projectMain, err := CreateProject(t, client, nil)
140 if err != nil {
141 t.Fatalf("Unable to create project: %v", err)
142 }
Joe Topjian8baf47a2017-01-11 21:50:24 -0700143 defer DeleteProject(t, client, projectMain.ID)
Joe Topjian8ad602c2017-01-11 21:01:47 -0700144
Joe Topjian66a046c2017-01-19 22:07:26 -0700145 tools.PrintResource(t, projectMain)
Joe Topjian8ad602c2017-01-11 21:01:47 -0700146
147 createOpts := projects.CreateOpts{
148 ParentID: projectMain.ID,
149 }
150
151 project, err := CreateProject(t, client, &createOpts)
152 if err != nil {
153 t.Fatalf("Unable to create project: %v", err)
154 }
Joe Topjian8baf47a2017-01-11 21:50:24 -0700155 defer DeleteProject(t, client, project.ID)
Joe Topjian8ad602c2017-01-11 21:01:47 -0700156
Joe Topjian66a046c2017-01-19 22:07:26 -0700157 tools.PrintResource(t, project)
Joe Topjian8ad602c2017-01-11 21:01:47 -0700158}