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 | |
| 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
| 9 | "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" |
| 10 | ) |
| 11 | |
| 12 | func TestProjectsList(t *testing.T) { |
| 13 | client, err := clients.NewIdentityV3Client() |
| 14 | if err != nil { |
Joe Topjian | 1c236d3 | 2017-01-09 15:33:32 -0700 | [diff] [blame] | 15 | t.Fatalf("Unable to obtain an identity client: %v", err) |
Joe Topjian | f61691c | 2016-11-05 12:34:59 -0600 | [diff] [blame] | 16 | } |
| 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 Topjian | 1c236d3 | 2017-01-09 15:33:32 -0700 | [diff] [blame] | 37 | |
| 38 | func 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 Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 62 | |
| 63 | func 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 Topjian | d131fb8 | 2017-01-11 21:41:44 -0700 | [diff] [blame] | 73 | defer DeleteProject(t, client, project.ID) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 74 | |
| 75 | PrintProject(t, project) |
Joe Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 76 | |
| 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 Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | func 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 Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 105 | defer DeleteProject(t, client, projectDomain.ID) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 106 | |
| 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 Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 117 | defer DeleteProject(t, client, project.ID) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 118 | |
| 119 | PrintProject(t, project) |
Joe Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 120 | |
| 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 Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | func 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 Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 142 | defer DeleteProject(t, client, projectMain.ID) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 143 | |
| 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 Topjian | 8baf47a | 2017-01-11 21:50:24 -0700 | [diff] [blame] | 154 | defer DeleteProject(t, client, project.ID) |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 155 | |
| 156 | PrintProject(t, project) |
| 157 | } |