blob: c89551373f1f511ef31e3e3eb476b74946d32f7f [file] [log] [blame]
Jon Perritta77ba0d2014-10-17 01:15:29 -05001// +build acceptance rackspace objectstorage v1
Jon Perritt8abd2c22014-10-16 20:28:51 -05002
3package v1
4
5import (
6 "testing"
7
8 osContainers "github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers"
9 "github.com/rackspace/gophercloud/pagination"
10 raxContainers "github.com/rackspace/gophercloud/rackspace/objectstorage/v1/containers"
11 th "github.com/rackspace/gophercloud/testhelper"
12)
13
14func TestContainers(t *testing.T) {
15 c, err := createClient(t, false)
16 th.AssertNoErr(t, err)
17
18 t.Logf("Containers Info available to the currently issued token:")
19 count := 0
20 err = raxContainers.List(c, &osContainers.ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) {
21 t.Logf("--- Page %02d ---", count)
22
23 containers, err := raxContainers.ExtractInfo(page)
24 th.AssertNoErr(t, err)
25
26 for i, container := range containers {
27 t.Logf("[%02d] name=[%s]", i, container.Name)
28 t.Logf(" count=[%d]", container.Count)
29 t.Logf(" bytes=[%d]", container.Bytes)
30 }
31
32 count++
33 return true, nil
34 })
35 th.AssertNoErr(t, err)
36 if count == 0 {
37 t.Errorf("No containers listed for your current token.")
38 }
39
40 t.Logf("Container Names available to the currently issued token:")
41 count = 0
42 err = raxContainers.List(c, &osContainers.ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) {
43 t.Logf("--- Page %02d ---", count)
44
45 names, err := raxContainers.ExtractNames(page)
46 th.AssertNoErr(t, err)
47
48 for i, name := range names {
49 t.Logf("[%02d] %s", i, name)
50 }
51
52 count++
53 return true, nil
54 })
55 th.AssertNoErr(t, err)
56 if count == 0 {
57 t.Errorf("No containers listed for your current token.")
58 }
59
Jon Perritta3de08f2014-12-17 22:08:19 -070060 createHeader, err := raxContainers.Create(c, "gophercloud-test", nil).Extract()
61 th.AssertNoErr(t, err)
62 t.Logf("Headers from Create Container request: %+v\n", createHeader)
Jon Perritt8abd2c22014-10-16 20:28:51 -050063 defer func() {
Jon Perritta3de08f2014-12-17 22:08:19 -070064 deleteres := raxContainers.Delete(c, "gophercloud-test")
65 deleteHeader, err := deleteres.Extract()
66 th.AssertNoErr(t, err)
67 t.Logf("Headers from Delete Container request: %+v\n", deleteres.Header)
68 t.Logf("Headers from Delete Container request: %+v\n", deleteHeader)
Jon Perritt8abd2c22014-10-16 20:28:51 -050069 }()
70
Jon Perritta3de08f2014-12-17 22:08:19 -070071 updateHeader, err := raxContainers.Update(c, "gophercloud-test", raxContainers.UpdateOpts{Metadata: map[string]string{"white": "mountains"}}).Extract()
72 th.AssertNoErr(t, err)
73 t.Logf("Headers from Update Container request: %+v\n", updateHeader)
Jon Perritt8abd2c22014-10-16 20:28:51 -050074 defer func() {
Jon Perritt7e70c402014-10-24 16:15:09 -050075 res := raxContainers.Update(c, "gophercloud-test", raxContainers.UpdateOpts{Metadata: map[string]string{"white": ""}})
76 th.AssertNoErr(t, res.Err)
Jon Perritt8abd2c22014-10-16 20:28:51 -050077 metadata, err := raxContainers.Get(c, "gophercloud-test").ExtractMetadata()
78 th.AssertNoErr(t, err)
Jon Perritta3de08f2014-12-17 22:08:19 -070079 t.Logf("Metadata from Get Container request (after update reverted): %+v\n", metadata)
Jon Perritt8abd2c22014-10-16 20:28:51 -050080 th.CheckEquals(t, metadata["White"], "")
81 }()
82
Jon Perritt7e70c402014-10-24 16:15:09 -050083 getres := raxContainers.Get(c, "gophercloud-test")
Jon Perritta3de08f2014-12-17 22:08:19 -070084 getHeader, err := getres.Extract()
Jon Perritt8abd2c22014-10-16 20:28:51 -050085 th.AssertNoErr(t, err)
Jon Perritta3de08f2014-12-17 22:08:19 -070086 t.Logf("Headers from Get Container request (after update): %+v\n", getHeader)
87 metadata, err := getres.ExtractMetadata()
88 t.Logf("Metadata from Get Container request (after update): %+v\n", metadata)
Jon Perritt8abd2c22014-10-16 20:28:51 -050089 th.CheckEquals(t, metadata["White"], "mountains")
90}