blob: f7ea48f926b0e710ab3c82698a2a9e131ff6ba40 [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 Topjiand131fb82017-01-11 21:41:44 -070041// DeleteProject will delete a project by ID. A fatal error will occur if
42// the project ID failed to be deleted. This works best when using it as
43// a deferred function.
44func DeleteProject(t *testing.T, client *gophercloud.ServiceClient, projectID string) {
45 err := projects.Delete(client, projectID).ExtractErr()
46 if err != nil {
47 t.Fatalf("Unable to delete project %s: %v", projectID, err)
48 }
49
50 t.Logf("Deleted project: %s", projectID)
51}
52
Joe Topjian918f5732016-08-15 08:47:08 -060053// PrintEndpoint will print an endpoint and all of its attributes.
54func PrintEndpoint(t *testing.T, endpoint *endpoints.Endpoint) {
55 t.Logf("ID: %s", endpoint.ID)
56 t.Logf("Availability: %s", endpoint.Availability)
57 t.Logf("Name: %s", endpoint.Name)
58 t.Logf("Region: %s", endpoint.Region)
59 t.Logf("ServiceID: %s", endpoint.ServiceID)
60 t.Logf("URL: %s", endpoint.URL)
61}
62
Joe Topjianf61691c2016-11-05 12:34:59 -060063// PrintProject will print a project and all of its attributes.
64func PrintProject(t *testing.T, project *projects.Project) {
65 t.Logf("ID: %s", project.ID)
66 t.Logf("IsDomain: %t", project.IsDomain)
67 t.Logf("Description: %s", project.Description)
68 t.Logf("DomainID: %s", project.DomainID)
69 t.Logf("Enabled: %t", project.Enabled)
70 t.Logf("Name: %s", project.Name)
71 t.Logf("ParentID: %s", project.ParentID)
72}
73
Joe Topjian918f5732016-08-15 08:47:08 -060074// PrintService will print a service and all of its attributes.
75func PrintService(t *testing.T, service *services.Service) {
76 t.Logf("ID: %s", service.ID)
77 t.Logf("Description: %s", service.Description)
78 t.Logf("Name: %s", service.Name)
79 t.Logf("Type: %s", service.Type)
80}
81
82// PrintToken will print a token and all of its attributes.
83func PrintToken(t *testing.T, token *tokens.Token) {
84 t.Logf("ID: %s", token.ID)
85 t.Logf("ExpiresAt: %v", token.ExpiresAt)
86}