Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 1 | // +build acceptance rackspace objectstorage v1 |
| 2 | |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 3 | package v1 |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | osContainers "github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers" |
| 9 | "github.com/rackspace/gophercloud/pagination" |
| 10 | raxCDNContainers "github.com/rackspace/gophercloud/rackspace/objectstorage/v1/cdncontainers" |
| 11 | raxContainers "github.com/rackspace/gophercloud/rackspace/objectstorage/v1/containers" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | ) |
| 14 | |
| 15 | func TestCDNContainers(t *testing.T) { |
| 16 | raxClient, err := createClient(t, false) |
| 17 | th.AssertNoErr(t, err) |
| 18 | |
Jon Perritt | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame] | 19 | createres := raxContainers.Create(raxClient, "gophercloud-test", nil) |
| 20 | th.AssertNoErr(t, createres.Err) |
| 21 | t.Logf("Headers from Create Container request: %+v\n", createres.Header) |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 22 | defer func() { |
Jon Perritt | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame] | 23 | res := raxContainers.Delete(raxClient, "gophercloud-test") |
| 24 | th.AssertNoErr(t, res.Err) |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 25 | }() |
| 26 | |
| 27 | raxCDNClient, err := createClient(t, true) |
| 28 | th.AssertNoErr(t, err) |
Jon Perritt | a3de08f | 2014-12-17 22:08:19 -0700 | [diff] [blame] | 29 | enableRes := raxCDNContainers.Enable(raxCDNClient, "gophercloud-test", raxCDNContainers.EnableOpts{CDNEnabled: true, TTL: 900}) |
| 30 | t.Logf("Header map from Enable CDN Container request: %+v\n", enableRes.Header) |
| 31 | enableHeader, err := enableRes.Extract() |
| 32 | th.AssertNoErr(t, err) |
| 33 | t.Logf("Headers from Enable CDN Container request: %+v\n", enableHeader) |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 34 | |
| 35 | t.Logf("Container Names available to the currently issued token:") |
| 36 | count := 0 |
| 37 | err = raxCDNContainers.List(raxCDNClient, &osContainers.ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) { |
| 38 | t.Logf("--- Page %02d ---", count) |
| 39 | |
| 40 | names, err := raxCDNContainers.ExtractNames(page) |
| 41 | th.AssertNoErr(t, err) |
| 42 | |
| 43 | for i, name := range names { |
| 44 | t.Logf("[%02d] %s", i, name) |
| 45 | } |
| 46 | |
| 47 | count++ |
| 48 | return true, nil |
| 49 | }) |
| 50 | th.AssertNoErr(t, err) |
| 51 | if count == 0 { |
Jon Perritt | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame] | 52 | t.Errorf("No CDN containers listed for your current token.") |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 53 | } |
| 54 | |
Jon Perritt | a3de08f | 2014-12-17 22:08:19 -0700 | [diff] [blame] | 55 | updateOpts := raxCDNContainers.UpdateOpts{XCDNEnabled: raxCDNContainers.Disabled, XLogRetention: raxCDNContainers.Enabled} |
| 56 | updateHeader, err := raxCDNContainers.Update(raxCDNClient, "gophercloud-test", updateOpts).Extract() |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 57 | th.AssertNoErr(t, err) |
Jon Perritt | a3de08f | 2014-12-17 22:08:19 -0700 | [diff] [blame] | 58 | t.Logf("Headers from Update CDN Container request: %+v\n", updateHeader) |
| 59 | |
| 60 | getRes := raxCDNContainers.Get(raxCDNClient, "gophercloud-test") |
| 61 | getHeader, err := getRes.Extract() |
| 62 | th.AssertNoErr(t, err) |
| 63 | t.Logf("Headers from Get CDN Container request (after update): %+v\n", getHeader) |
| 64 | metadata, err := getRes.ExtractMetadata() |
| 65 | t.Logf("Metadata from Get CDN Container request (after update): %+v\n", metadata) |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 66 | } |