blob: d22057b469099c99413106a93883e5fab349fcd5 [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
60 headers, err := raxContainers.Create(c, "gophercloud-test", nil).ExtractHeaders()
61 th.AssertNoErr(t, err)
62 defer func() {
63 _, err := raxContainers.Delete(c, "gophercloud-test").ExtractHeaders()
64 th.AssertNoErr(t, err)
65 }()
66
67 headers, err = raxContainers.Update(c, "gophercloud-test", raxContainers.UpdateOpts{Metadata: map[string]string{"white": "mountains"}}).ExtractHeaders()
68 th.AssertNoErr(t, err)
69 t.Logf("Headers from Update Account request: %+v\n", headers)
70 defer func() {
71 _, err := raxContainers.Update(c, "gophercloud-test", raxContainers.UpdateOpts{Metadata: map[string]string{"white": ""}}).ExtractHeaders()
72 th.AssertNoErr(t, err)
73 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
79 getResult := raxContainers.Get(c, "gophercloud-test")
80 headers, err = getResult.ExtractHeaders()
81 th.AssertNoErr(t, err)
82 t.Logf("Headers from Get Account request (after update): %+v\n", headers)
83 metadata, err := getResult.ExtractMetadata()
84 th.AssertNoErr(t, err)
85 t.Logf("Metadata from Get Account request (after update): %+v\n", metadata)
86 th.CheckEquals(t, metadata["White"], "mountains")
87}