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 | |
Ash Wilson | fef72b8 | 2014-10-24 15:46:45 -0400 | [diff] [blame] | 19 | headers, err := raxContainers.Create(raxClient, "gophercloud-test", nil).Extract() |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 20 | th.AssertNoErr(t, err) |
| 21 | t.Logf("Headers from Create Container request: %+v\n", headers) |
| 22 | defer func() { |
Ash Wilson | fef72b8 | 2014-10-24 15:46:45 -0400 | [diff] [blame] | 23 | _, err := raxContainers.Delete(raxClient, "gophercloud-test").Extract() |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 24 | th.AssertNoErr(t, err) |
| 25 | }() |
| 26 | |
| 27 | raxCDNClient, err := createClient(t, true) |
| 28 | th.AssertNoErr(t, err) |
| 29 | |
Ash Wilson | fef72b8 | 2014-10-24 15:46:45 -0400 | [diff] [blame] | 30 | r := raxCDNContainers.Enable(raxCDNClient, "gophercloud-test", raxCDNContainers.EnableOpts{CDNEnabled: true, TTL: 900}) |
| 31 | th.AssertNoErr(t, r.Err) |
| 32 | t.Logf("Headers from Enable CDN Container request: %+v\n", r.Header) |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 33 | |
| 34 | t.Logf("Container Names available to the currently issued token:") |
| 35 | count := 0 |
| 36 | err = raxCDNContainers.List(raxCDNClient, &osContainers.ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) { |
| 37 | t.Logf("--- Page %02d ---", count) |
| 38 | |
| 39 | names, err := raxCDNContainers.ExtractNames(page) |
| 40 | th.AssertNoErr(t, err) |
| 41 | |
| 42 | for i, name := range names { |
| 43 | t.Logf("[%02d] %s", i, name) |
| 44 | } |
| 45 | |
| 46 | count++ |
| 47 | return true, nil |
| 48 | }) |
| 49 | th.AssertNoErr(t, err) |
| 50 | if count == 0 { |
| 51 | t.Errorf("No containers listed for your current token.") |
| 52 | } |
| 53 | |
Ash Wilson | fef72b8 | 2014-10-24 15:46:45 -0400 | [diff] [blame] | 54 | headers, err = raxCDNContainers.Update(raxCDNClient, "gophercloud-test", raxCDNContainers.UpdateOpts{CDNEnabled: false}).Extract() |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 55 | th.AssertNoErr(t, err) |
| 56 | t.Logf("Headers from Update CDN Container request: %+v\n", headers) |
| 57 | |
Ash Wilson | fef72b8 | 2014-10-24 15:46:45 -0400 | [diff] [blame] | 58 | metadata, err := raxCDNContainers.Get(raxCDNClient, "gophercloud-test").ExtractMetadata() |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 59 | th.AssertNoErr(t, err) |
Ash Wilson | fef72b8 | 2014-10-24 15:46:45 -0400 | [diff] [blame] | 60 | t.Logf("Headers from Get CDN Container request (after update): %+v\n", metadata) |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 61 | } |