Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 1 | package containers |
| 2 | |
| 3 | import ( |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 4 | "testing" |
| 5 | |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud/pagination" |
Jon Perritt | 27caa2f | 2014-10-13 21:08:36 -0500 | [diff] [blame] | 7 | th "github.com/rackspace/gophercloud/testhelper" |
Jamie Hannaford | 4ff7996 | 2014-10-06 16:28:23 +0200 | [diff] [blame] | 8 | fake "github.com/rackspace/gophercloud/testhelper/client" |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 9 | ) |
| 10 | |
| 11 | var metadata = map[string]string{"gophercloud-test": "containers"} |
| 12 | |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 13 | func TestListContainerInfo(t *testing.T) { |
Jon Perritt | 27caa2f | 2014-10-13 21:08:36 -0500 | [diff] [blame] | 14 | th.SetupHTTP() |
| 15 | defer th.TeardownHTTP() |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 16 | HandleListContainerInfoSuccessfully(t) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 17 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 18 | count := 0 |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 19 | err := List(fake.ServiceClient(), &ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) { |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 20 | count++ |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 21 | actual, err := ExtractInfo(page) |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 22 | th.AssertNoErr(t, err) |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 23 | |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 24 | th.CheckDeepEquals(t, ExpectedListInfo, actual) |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 25 | |
| 26 | return true, nil |
| 27 | }) |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 28 | th.AssertNoErr(t, err) |
| 29 | th.CheckEquals(t, count, 1) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | func TestListContainerNames(t *testing.T) { |
Jon Perritt | 27caa2f | 2014-10-13 21:08:36 -0500 | [diff] [blame] | 33 | th.SetupHTTP() |
| 34 | defer th.TeardownHTTP() |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 35 | HandleListContainerNamesSuccessfully(t) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 36 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 37 | count := 0 |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 38 | err := List(fake.ServiceClient(), &ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) { |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 39 | count++ |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 40 | actual, err := ExtractNames(page) |
| 41 | if err != nil { |
| 42 | t.Errorf("Failed to extract container names: %v", err) |
| 43 | return false, err |
| 44 | } |
| 45 | |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 46 | th.CheckDeepEquals(t, ExpectedListNames, actual) |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 47 | |
| 48 | return true, nil |
| 49 | }) |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 50 | th.AssertNoErr(t, err) |
| 51 | th.CheckEquals(t, count, 1) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | func TestCreateContainer(t *testing.T) { |
Jon Perritt | 27caa2f | 2014-10-13 21:08:36 -0500 | [diff] [blame] | 55 | th.SetupHTTP() |
| 56 | defer th.TeardownHTTP() |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 57 | HandleCreateContainerSuccessfully(t) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 58 | |
Jon Perritt | 27caa2f | 2014-10-13 21:08:36 -0500 | [diff] [blame] | 59 | options := CreateOpts{ContentType: "application/json", Metadata: map[string]string{"foo": "bar"}} |
Jon Perritt | 0ce24ad | 2014-10-20 21:59:45 -0500 | [diff] [blame] | 60 | res := Create(fake.ServiceClient(), "testContainer", options) |
Jon Perritt | 59b0ea4 | 2015-01-31 20:23:33 -0700 | [diff] [blame^] | 61 | c, err := res.Extract() |
| 62 | th.CheckNoErr(t, err) |
Jon Perritt | 0ce24ad | 2014-10-20 21:59:45 -0500 | [diff] [blame] | 63 | th.CheckEquals(t, "bar", res.Header["X-Container-Meta-Foo"][0]) |
Jon Perritt | 59b0ea4 | 2015-01-31 20:23:33 -0700 | [diff] [blame^] | 64 | th.CheckEquals(t, "1234567", c.TransID) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | func TestDeleteContainer(t *testing.T) { |
Jon Perritt | 27caa2f | 2014-10-13 21:08:36 -0500 | [diff] [blame] | 68 | th.SetupHTTP() |
| 69 | defer th.TeardownHTTP() |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 70 | HandleDeleteContainerSuccessfully(t) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 71 | |
Jon Perritt | 0ce24ad | 2014-10-20 21:59:45 -0500 | [diff] [blame] | 72 | res := Delete(fake.ServiceClient(), "testContainer") |
| 73 | th.CheckNoErr(t, res.Err) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | func TestUpateContainer(t *testing.T) { |
Jon Perritt | 27caa2f | 2014-10-13 21:08:36 -0500 | [diff] [blame] | 77 | th.SetupHTTP() |
| 78 | defer th.TeardownHTTP() |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 79 | HandleUpdateContainerSuccessfully(t) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 80 | |
Jon Perritt | 27caa2f | 2014-10-13 21:08:36 -0500 | [diff] [blame] | 81 | options := &UpdateOpts{Metadata: map[string]string{"foo": "bar"}} |
Jon Perritt | 0ce24ad | 2014-10-20 21:59:45 -0500 | [diff] [blame] | 82 | res := Update(fake.ServiceClient(), "testContainer", options) |
| 83 | th.CheckNoErr(t, res.Err) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | func TestGetContainer(t *testing.T) { |
Jon Perritt | 27caa2f | 2014-10-13 21:08:36 -0500 | [diff] [blame] | 87 | th.SetupHTTP() |
| 88 | defer th.TeardownHTTP() |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 89 | HandleGetContainerSuccessfully(t) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 90 | |
Jamie Hannaford | 4ff7996 | 2014-10-06 16:28:23 +0200 | [diff] [blame] | 91 | _, err := Get(fake.ServiceClient(), "testContainer").ExtractMetadata() |
Jon Perritt | 457f8ca | 2014-10-15 00:28:23 -0500 | [diff] [blame] | 92 | th.CheckNoErr(t, err) |
Jon Perritt | 50da9b4 | 2014-09-14 15:06:59 -0500 | [diff] [blame] | 93 | } |