blob: 3276efcd36be301c3b48082006ec783b1e66212d [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 Topjianf61691c2016-11-05 12:34:59 -06008 "github.com/gophercloud/gophercloud/openstack/identity/v3/projects"
Joe Topjian918f5732016-08-15 08:47:08 -06009)
10
Joe Topjian8ad602c2017-01-11 21:01:47 -070011// 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.
15func 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 Topjiand131fb82017-01-11 21:41:44 -070038// 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.
41func 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}