blob: 5bed8a477ac0e10973323887da8e75853a178910 [file] [log] [blame]
Joe Topjian918f5732016-08-15 08:47:08 -06001package v3
2
3import (
4 "testing"
5
Joe Topjian8ad602c2017-01-11 21:01:47 -07006 "github.com/gophercloud/gophercloud"
7 "github.com/gophercloud/gophercloud/acceptance/tools"
Joe Topjian918f5732016-08-15 08:47:08 -06008 "github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints"
Joe Topjianf61691c2016-11-05 12:34:59 -06009 "github.com/gophercloud/gophercloud/openstack/identity/v3/projects"
Joe Topjian918f5732016-08-15 08:47:08 -060010 "github.com/gophercloud/gophercloud/openstack/identity/v3/services"
11 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
12)
13
Joe Topjian8ad602c2017-01-11 21:01:47 -070014// 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.
18func 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 Topjian918f5732016-08-15 08:47:08 -060041// PrintEndpoint will print an endpoint and all of its attributes.
42func 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 Topjianf61691c2016-11-05 12:34:59 -060051// PrintProject will print a project and all of its attributes.
52func 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 Topjian918f5732016-08-15 08:47:08 -060062// PrintService will print a service and all of its attributes.
63func 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.
71func PrintToken(t *testing.T, token *tokens.Token) {
72 t.Logf("ID: %s", token.ID)
73 t.Logf("ExpiresAt: %v", token.ExpiresAt)
74}