Jon Perritt | a77ba0d | 2014-10-17 01:15:29 -0500 | [diff] [blame] | 1 | // +build acceptance rackspace objectstorage v1 |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 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 | |
| 14 | func 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 Perritt | a3de08f | 2014-12-17 22:08:19 -0700 | [diff] [blame^] | 60 | 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 Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 63 | defer func() { |
Jon Perritt | a3de08f | 2014-12-17 22:08:19 -0700 | [diff] [blame^] | 64 | 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 Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 69 | }() |
| 70 | |
Jon Perritt | a3de08f | 2014-12-17 22:08:19 -0700 | [diff] [blame^] | 71 | 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 Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 74 | defer func() { |
Jon Perritt | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame] | 75 | res := raxContainers.Update(c, "gophercloud-test", raxContainers.UpdateOpts{Metadata: map[string]string{"white": ""}}) |
| 76 | th.AssertNoErr(t, res.Err) |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 77 | metadata, err := raxContainers.Get(c, "gophercloud-test").ExtractMetadata() |
| 78 | th.AssertNoErr(t, err) |
Jon Perritt | a3de08f | 2014-12-17 22:08:19 -0700 | [diff] [blame^] | 79 | t.Logf("Metadata from Get Container request (after update reverted): %+v\n", metadata) |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 80 | th.CheckEquals(t, metadata["White"], "") |
| 81 | }() |
| 82 | |
Jon Perritt | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame] | 83 | getres := raxContainers.Get(c, "gophercloud-test") |
Jon Perritt | a3de08f | 2014-12-17 22:08:19 -0700 | [diff] [blame^] | 84 | getHeader, err := getres.Extract() |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 85 | th.AssertNoErr(t, err) |
Jon Perritt | a3de08f | 2014-12-17 22:08:19 -0700 | [diff] [blame^] | 86 | 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 Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 89 | th.CheckEquals(t, metadata["White"], "mountains") |
| 90 | } |