Joe Topjian | f61691c | 2016-11-05 12:34:59 -0600 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v3 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame] | 8 | "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 Topjian | f61691c | 2016-11-05 12:34:59 -0600 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | func TestProjectsList(t *testing.T) { |
| 14 | client, err := clients.NewIdentityV3Client() |
| 15 | if err != nil { |
Joe Topjian | 1c236d3 | 2017-01-09 15:33:32 -0700 | [diff] [blame] | 16 | t.Fatalf("Unable to obtain an identity client: %v", err) |
Joe Topjian | f61691c | 2016-11-05 12:34:59 -0600 | [diff] [blame] | 17 | } |
| 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 Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 35 | tools.PrintResource(t, project) |
Joe Topjian | f61691c | 2016-11-05 12:34:59 -0600 | [diff] [blame] | 36 | } |
| 37 | } |
Joe Topjian | 1c236d3 | 2017-01-09 15:33:32 -0700 | [diff] [blame] | 38 | |
| 39 | func 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 Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 61 | tools.PrintResource(t, p) |
Joe Topjian | 1c236d3 | 2017-01-09 15:33:32 -0700 | [diff] [blame] | 62 | } |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 63 | |
| 64 | func 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 Topjian | d131fb8 | 2017-01-11 21:41:44 -0700 | [diff] [blame] | 74 | defer DeleteProject(t, client, project.ID) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 75 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 76 | tools.PrintResource(t, project) |
Joe Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 77 | |
| 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 Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 88 | tools.PrintResource(t, updatedProject) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | func 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 Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 106 | defer DeleteProject(t, client, projectDomain.ID) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 107 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 108 | tools.PrintResource(t, projectDomain) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 109 | |
| 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 Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 118 | defer DeleteProject(t, client, project.ID) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 119 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 120 | tools.PrintResource(t, project) |
Joe Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 121 | |
| 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 Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | func 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 Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 143 | defer DeleteProject(t, client, projectMain.ID) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 144 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 145 | tools.PrintResource(t, projectMain) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 146 | |
| 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 Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 155 | defer DeleteProject(t, client, project.ID) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 156 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 157 | tools.PrintResource(t, project) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 158 | } |