Joe Topjian | f61691c | 2016-11-05 12:34:59 -0600 | [diff] [blame] | 1 | package testing |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" |
| 7 | "github.com/gophercloud/gophercloud/pagination" |
| 8 | th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | "github.com/gophercloud/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
| 12 | func TestListProjects(t *testing.T) { |
| 13 | th.SetupHTTP() |
| 14 | defer th.TeardownHTTP() |
| 15 | HandleListProjectsSuccessfully(t) |
| 16 | |
| 17 | count := 0 |
| 18 | err := projects.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { |
| 19 | count++ |
| 20 | |
| 21 | actual, err := projects.ExtractProjects(page) |
| 22 | th.AssertNoErr(t, err) |
| 23 | |
| 24 | th.CheckDeepEquals(t, ExpectedProjectSlice, actual) |
| 25 | |
| 26 | return true, nil |
| 27 | }) |
| 28 | th.AssertNoErr(t, err) |
| 29 | th.CheckEquals(t, count, 1) |
| 30 | } |
Joe Topjian | 1c236d3 | 2017-01-09 15:33:32 -0700 | [diff] [blame] | 31 | |
| 32 | func TestGetProject(t *testing.T) { |
| 33 | th.SetupHTTP() |
| 34 | defer th.TeardownHTTP() |
| 35 | HandleGetProjectSuccessfully(t) |
| 36 | |
| 37 | actual, err := projects.Get(client.ServiceClient(), "1234", nil).Extract() |
| 38 | th.AssertNoErr(t, err) |
| 39 | th.CheckDeepEquals(t, RedTeam, *actual) |
| 40 | } |
Joe Topjian | 8ad602c | 2017-01-11 21:01:47 -0700 | [diff] [blame] | 41 | |
| 42 | func TestCreateProject(t *testing.T) { |
| 43 | th.SetupHTTP() |
| 44 | defer th.TeardownHTTP() |
| 45 | HandleCreateProjectSuccessfully(t) |
| 46 | |
| 47 | createOpts := projects.CreateOpts{ |
| 48 | Name: "Red Team", |
| 49 | Description: "The team that is red", |
| 50 | } |
| 51 | |
| 52 | actual, err := projects.Create(client.ServiceClient(), createOpts).Extract() |
| 53 | th.AssertNoErr(t, err) |
| 54 | th.CheckDeepEquals(t, RedTeam, *actual) |
| 55 | } |
Joe Topjian | d131fb8 | 2017-01-11 21:41:44 -0700 | [diff] [blame^] | 56 | |
| 57 | func TestDeleteProject(t *testing.T) { |
| 58 | th.SetupHTTP() |
| 59 | defer th.TeardownHTTP() |
| 60 | HandleDeleteProjectSuccessfully(t) |
| 61 | |
| 62 | res := projects.Delete(client.ServiceClient(), "1234") |
| 63 | th.AssertNoErr(t, res.Err) |
| 64 | } |