Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 1 | package v3 |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 6 | "github.com/gophercloud/gophercloud" |
| 7 | "github.com/gophercloud/gophercloud/acceptance/tools" |
Joe Topjian | f61691c | 2016-11-05 12:34:59 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 9 | ) |
| 10 | |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 11 | // CreateProject will create a project with a random name. |
| 12 | // It takes an optional createOpts parameter since creating a project |
| 13 | // has so many options. An error will be returned if the project was |
| 14 | // unable to be created. |
| 15 | func CreateProject(t *testing.T, client *gophercloud.ServiceClient, c *projects.CreateOpts) (*projects.Project, error) { |
| 16 | name := tools.RandomString("ACPTTEST", 8) |
| 17 | t.Logf("Attempting to create project: %s", name) |
| 18 | |
| 19 | var createOpts projects.CreateOpts |
| 20 | if c != nil { |
| 21 | createOpts = *c |
| 22 | } else { |
| 23 | createOpts = projects.CreateOpts{} |
| 24 | } |
| 25 | |
| 26 | createOpts.Name = name |
| 27 | |
| 28 | project, err := projects.Create(client, createOpts).Extract() |
| 29 | if err != nil { |
| 30 | return project, err |
| 31 | } |
| 32 | |
| 33 | t.Logf("Successfully created project %s with ID %s", name, project.ID) |
| 34 | |
| 35 | return project, nil |
| 36 | } |
| 37 | |
Joe Topjian | d131fb8 | 2017-01-11 21:41:44 -0700 | [diff] [blame] | 38 | // DeleteProject will delete a project by ID. A fatal error will occur if |
| 39 | // the project ID failed to be deleted. This works best when using it as |
| 40 | // a deferred function. |
| 41 | func DeleteProject(t *testing.T, client *gophercloud.ServiceClient, projectID string) { |
| 42 | err := projects.Delete(client, projectID).ExtractErr() |
| 43 | if err != nil { |
| 44 | t.Fatalf("Unable to delete project %s: %v", projectID, err) |
| 45 | } |
| 46 | |
| 47 | t.Logf("Deleted project: %s", projectID) |
| 48 | } |