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) |
| 76 | } |
| 77 | |
| 78 | func TestProjectsDomain(t *testing.T) { |
| 79 | client, err := clients.NewIdentityV3Client() |
| 80 | if err != nil { |
| 81 | t.Fatalf("Unable to obtain an identity client: %v") |
| 82 | } |
| 83 | |
| 84 | var iTrue = true |
| 85 | createOpts := projects.CreateOpts{ |
| 86 | IsDomain: &iTrue, |
| 87 | } |
| 88 | |
| 89 | projectDomain, err := CreateProject(t, client, &createOpts) |
| 90 | if err != nil { |
| 91 | t.Fatalf("Unable to create project: %v", err) |
| 92 | } |
| 93 | |
| 94 | PrintProject(t, projectDomain) |
| 95 | |
| 96 | createOpts = projects.CreateOpts{ |
| 97 | DomainID: projectDomain.ID, |
| 98 | } |
| 99 | |
| 100 | project, err := CreateProject(t, client, &createOpts) |
| 101 | if err != nil { |
| 102 | t.Fatalf("Unable to create project: %v", err) |
| 103 | } |
| 104 | |
| 105 | PrintProject(t, project) |
| 106 | } |
| 107 | |
| 108 | func TestProjectsNested(t *testing.T) { |
| 109 | client, err := clients.NewIdentityV3Client() |
| 110 | if err != nil { |
| 111 | t.Fatalf("Unable to obtain an identity client: %v") |
| 112 | } |
| 113 | |
| 114 | projectMain, err := CreateProject(t, client, nil) |
| 115 | if err != nil { |
| 116 | t.Fatalf("Unable to create project: %v", err) |
| 117 | } |
| 118 | |
| 119 | PrintProject(t, projectMain) |
| 120 | |
| 121 | createOpts := projects.CreateOpts{ |
| 122 | ParentID: projectMain.ID, |
| 123 | } |
| 124 | |
| 125 | project, err := CreateProject(t, client, &createOpts) |
| 126 | if err != nil { |
| 127 | t.Fatalf("Unable to create project: %v", err) |
| 128 | } |
| 129 | |
| 130 | PrintProject(t, project) |
| 131 | } |