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