blob: a7339cf38846c324743a0dfa6ee0009068bbec9c [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 Perritt7e70c402014-10-24 16:15:09 -050060 createres := raxContainers.Create(c, "gophercloud-test", nil)
61 th.AssertNoErr(t, createres.Err)
Jon Perritt8abd2c22014-10-16 20:28:51 -050062 defer func() {
Jon Perritt7e70c402014-10-24 16:15:09 -050063 res := raxContainers.Delete(c, "gophercloud-test")
64 th.AssertNoErr(t, res.Err)
Jon Perritt8abd2c22014-10-16 20:28:51 -050065 }()
66
Jon Perritt7e70c402014-10-24 16:15:09 -050067 updateres := raxContainers.Update(c, "gophercloud-test", raxContainers.UpdateOpts{Metadata: map[string]string{"white": "mountains"}})
68 th.AssertNoErr(t, updateres.Err)
69 t.Logf("Headers from Update Account request: %+v\n", updateres.Header)
Jon Perritt8abd2c22014-10-16 20:28:51 -050070 defer func() {
Jon Perritt7e70c402014-10-24 16:15:09 -050071 res := raxContainers.Update(c, "gophercloud-test", raxContainers.UpdateOpts{Metadata: map[string]string{"white": ""}})
72 th.AssertNoErr(t, res.Err)
Jon Perritt8abd2c22014-10-16 20:28:51 -050073 metadata, err := raxContainers.Get(c, "gophercloud-test").ExtractMetadata()
74 th.AssertNoErr(t, err)
75 t.Logf("Metadata from Get Account request (after update reverted): %+v\n", metadata)
76 th.CheckEquals(t, metadata["White"], "")
77 }()
78
Jon Perritt7e70c402014-10-24 16:15:09 -050079 getres := raxContainers.Get(c, "gophercloud-test")
80 t.Logf("Headers from Get Account request (after update): %+v\n", getres.Header)
81 metadata, err := getres.ExtractMetadata()
Jon Perritt8abd2c22014-10-16 20:28:51 -050082 th.AssertNoErr(t, err)
83 t.Logf("Metadata from Get Account request (after update): %+v\n", metadata)
84 th.CheckEquals(t, metadata["White"], "mountains")
85}