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 | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints" |
Joe Topjian | f61691c | 2016-11-05 12:34:59 -0600 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud/openstack/identity/v3/services" |
| 11 | "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" |
| 12 | ) |
| 13 | |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame^] | 14 | // CreateProject will create a project with a random name. |
| 15 | // It takes an optional createOpts parameter since creating a project |
| 16 | // has so many options. An error will be returned if the project was |
| 17 | // unable to be created. |
| 18 | func CreateProject(t *testing.T, client *gophercloud.ServiceClient, c *projects.CreateOpts) (*projects.Project, error) { |
| 19 | name := tools.RandomString("ACPTTEST", 8) |
| 20 | t.Logf("Attempting to create project: %s", name) |
| 21 | |
| 22 | var createOpts projects.CreateOpts |
| 23 | if c != nil { |
| 24 | createOpts = *c |
| 25 | } else { |
| 26 | createOpts = projects.CreateOpts{} |
| 27 | } |
| 28 | |
| 29 | createOpts.Name = name |
| 30 | |
| 31 | project, err := projects.Create(client, createOpts).Extract() |
| 32 | if err != nil { |
| 33 | return project, err |
| 34 | } |
| 35 | |
| 36 | t.Logf("Successfully created project %s with ID %s", name, project.ID) |
| 37 | |
| 38 | return project, nil |
| 39 | } |
| 40 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 41 | // PrintEndpoint will print an endpoint and all of its attributes. |
| 42 | func PrintEndpoint(t *testing.T, endpoint *endpoints.Endpoint) { |
| 43 | t.Logf("ID: %s", endpoint.ID) |
| 44 | t.Logf("Availability: %s", endpoint.Availability) |
| 45 | t.Logf("Name: %s", endpoint.Name) |
| 46 | t.Logf("Region: %s", endpoint.Region) |
| 47 | t.Logf("ServiceID: %s", endpoint.ServiceID) |
| 48 | t.Logf("URL: %s", endpoint.URL) |
| 49 | } |
| 50 | |
Joe Topjian | f61691c | 2016-11-05 12:34:59 -0600 | [diff] [blame] | 51 | // PrintProject will print a project and all of its attributes. |
| 52 | func PrintProject(t *testing.T, project *projects.Project) { |
| 53 | t.Logf("ID: %s", project.ID) |
| 54 | t.Logf("IsDomain: %t", project.IsDomain) |
| 55 | t.Logf("Description: %s", project.Description) |
| 56 | t.Logf("DomainID: %s", project.DomainID) |
| 57 | t.Logf("Enabled: %t", project.Enabled) |
| 58 | t.Logf("Name: %s", project.Name) |
| 59 | t.Logf("ParentID: %s", project.ParentID) |
| 60 | } |
| 61 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 62 | // PrintService will print a service and all of its attributes. |
| 63 | func PrintService(t *testing.T, service *services.Service) { |
| 64 | t.Logf("ID: %s", service.ID) |
| 65 | t.Logf("Description: %s", service.Description) |
| 66 | t.Logf("Name: %s", service.Name) |
| 67 | t.Logf("Type: %s", service.Type) |
| 68 | } |
| 69 | |
| 70 | // PrintToken will print a token and all of its attributes. |
| 71 | func PrintToken(t *testing.T, token *tokens.Token) { |
| 72 | t.Logf("ID: %s", token.ID) |
| 73 | t.Logf("ExpiresAt: %v", token.ExpiresAt) |
| 74 | } |