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 | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame^] | 60 | createres := raxContainers.Create(c, "gophercloud-test", nil) |
| 61 | th.AssertNoErr(t, createres.Err) |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 62 | defer func() { |
Jon Perritt | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame^] | 63 | res := raxContainers.Delete(c, "gophercloud-test") |
| 64 | th.AssertNoErr(t, res.Err) |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 65 | }() |
| 66 | |
Jon Perritt | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame^] | 67 | 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 Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 70 | defer func() { |
Jon Perritt | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame^] | 71 | res := raxContainers.Update(c, "gophercloud-test", raxContainers.UpdateOpts{Metadata: map[string]string{"white": ""}}) |
| 72 | th.AssertNoErr(t, res.Err) |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 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 | |
Jon Perritt | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame^] | 79 | 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 Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 82 | 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 | } |