blob: 7ba4eb21c6870bc15d8819d42484d874bd9539c5 [file] [log] [blame]
Jon Perritt0e28b112014-10-14 20:49:31 -05001package containers
Jon Perritt457f8ca2014-10-15 00:28:23 -05002
3import (
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
12func 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
31func 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
53func 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 Perritt260e0882014-10-20 23:31:23 -050059 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 Perritt457f8ca2014-10-15 00:28:23 -050062
63}
64
65func TestDeleteContainers(t *testing.T) {
66 th.SetupHTTP()
67 defer th.TeardownHTTP()
68 os.HandleDeleteContainerSuccessfully(t)
69
Jon Perritt260e0882014-10-20 23:31:23 -050070 res := Delete(fake.ServiceClient(), "testContainer")
71 th.CheckNoErr(t, res.Err)
Jon Perritt457f8ca2014-10-15 00:28:23 -050072}
73
74func 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 Perritt260e0882014-10-20 23:31:23 -050080 res := Update(fake.ServiceClient(), "testContainer", options)
81 th.CheckNoErr(t, res.Err)
Jon Perritt457f8ca2014-10-15 00:28:23 -050082}
83
84func 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}