rax cdnobjects unit test
diff --git a/acceptance/rackspace/objectstorage/v1/cdncontainers_test.go b/acceptance/rackspace/objectstorage/v1/cdncontainers_test.go
index b7b1f99..2765f00 100644
--- a/acceptance/rackspace/objectstorage/v1/cdncontainers_test.go
+++ b/acceptance/rackspace/objectstorage/v1/cdncontainers_test.go
@@ -1 +1,61 @@
+// +build acceptance rackspace objectstorage v1
+
package v1
+
+import (
+ "testing"
+
+ osContainers "github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers"
+ "github.com/rackspace/gophercloud/pagination"
+ raxCDNContainers "github.com/rackspace/gophercloud/rackspace/objectstorage/v1/cdncontainers"
+ raxContainers "github.com/rackspace/gophercloud/rackspace/objectstorage/v1/containers"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestCDNContainers(t *testing.T) {
+ raxClient, err := createClient(t, false)
+ th.AssertNoErr(t, err)
+
+ headers, err := raxContainers.Create(raxClient, "gophercloud-test", nil).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ t.Logf("Headers from Create Container request: %+v\n", headers)
+ defer func() {
+ _, err := raxContainers.Delete(raxClient, "gophercloud-test").ExtractHeaders()
+ th.AssertNoErr(t, err)
+ }()
+
+ raxCDNClient, err := createClient(t, true)
+ th.AssertNoErr(t, err)
+
+ headers, err = raxCDNContainers.Enable(raxCDNClient, "gophercloud-test", raxCDNContainers.EnableOpts{CDNEnabled: true, TTL: 900}).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ t.Logf("Headers from Enable CDN Container request: %+v\n", headers)
+
+ t.Logf("Container Names available to the currently issued token:")
+ count := 0
+ err = raxCDNContainers.List(raxCDNClient, &osContainers.ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) {
+ t.Logf("--- Page %02d ---", count)
+
+ names, err := raxCDNContainers.ExtractNames(page)
+ th.AssertNoErr(t, err)
+
+ for i, name := range names {
+ t.Logf("[%02d] %s", i, name)
+ }
+
+ count++
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ if count == 0 {
+ t.Errorf("No containers listed for your current token.")
+ }
+
+ headers, err = raxCDNContainers.Update(raxCDNClient, "gophercloud-test", raxCDNContainers.UpdateOpts{CDNEnabled: false}).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ t.Logf("Headers from Update CDN Container request: %+v\n", headers)
+
+ headers, err = raxCDNContainers.Get(raxCDNClient, "gophercloud-test").ExtractHeaders()
+ th.AssertNoErr(t, err)
+ t.Logf("Headers from Get CDN Container request (after update): %+v\n", headers)
+}
diff --git a/acceptance/rackspace/objectstorage/v1/cdnobjects_test.go b/acceptance/rackspace/objectstorage/v1/cdnobjects_test.go
index b7b1f99..2d816f0 100644
--- a/acceptance/rackspace/objectstorage/v1/cdnobjects_test.go
+++ b/acceptance/rackspace/objectstorage/v1/cdnobjects_test.go
@@ -1 +1,46 @@
+// +build acceptance rackspace objectstorage v1
+
package v1
+
+import (
+ "bytes"
+ "testing"
+
+ raxCDNContainers "github.com/rackspace/gophercloud/rackspace/objectstorage/v1/cdncontainers"
+ raxCDNObjects "github.com/rackspace/gophercloud/rackspace/objectstorage/v1/cdnobjects"
+ raxContainers "github.com/rackspace/gophercloud/rackspace/objectstorage/v1/containers"
+ raxObjects "github.com/rackspace/gophercloud/rackspace/objectstorage/v1/objects"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestCDNObjects(t *testing.T) {
+ raxClient, err := createClient(t, false)
+ th.AssertNoErr(t, err)
+
+ headers, err := raxContainers.Create(raxClient, "gophercloud-test", nil).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ t.Logf("Headers from Create Container request: %+v\n", headers)
+ defer func() {
+ _, err := raxContainers.Delete(raxClient, "gophercloud-test").ExtractHeaders()
+ th.AssertNoErr(t, err)
+ }()
+
+ headers, err = raxObjects.Create(raxClient, "gophercloud-test", "test-object", bytes.NewBufferString("gophercloud cdn test"), nil).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ t.Logf("Headers from Create Object request: %+v\n", headers)
+ defer func() {
+ _, err := raxObjects.Delete(raxClient, "gophercloud-test", "test-object", nil).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ }()
+
+ raxCDNClient, err := createClient(t, true)
+ th.AssertNoErr(t, err)
+
+ headers, err = raxCDNContainers.Enable(raxCDNClient, "gophercloud-test", raxCDNContainers.EnableOpts{CDNEnabled: true, TTL: 900}).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ t.Logf("Headers from Enable CDN Container request: %+v\n", headers)
+
+ headers, err = raxCDNObjects.Delete(raxCDNClient, "gophercloud-test", "test-object", nil).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ t.Logf("Headers from Delete CDN Object request: %+v\n", headers)
+}
diff --git a/openstack/objectstorage/v1/containers/requests.go b/openstack/objectstorage/v1/containers/requests.go
index f81b3ed..89fa014 100644
--- a/openstack/objectstorage/v1/containers/requests.go
+++ b/openstack/objectstorage/v1/containers/requests.go
@@ -125,7 +125,7 @@
var res DeleteResult
resp, err := perigee.Request("DELETE", deleteURL(c, containerName), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- OkCodes: []int{204},
+ OkCodes: []int{202, 204},
})
res.Header = resp.HttpResponse.Header
res.Err = err
@@ -184,7 +184,7 @@
resp, err := perigee.Request("POST", updateURL(c, containerName), perigee.Options{
MoreHeaders: h,
- OkCodes: []int{204},
+ OkCodes: []int{202, 204},
})
res.Header = resp.HttpResponse.Header
res.Err = err
diff --git a/rackspace/objectstorage/v1/cdncontainers/delegate.go b/rackspace/objectstorage/v1/cdncontainers/delegate.go
index f5e8cdd..d7eef20 100644
--- a/rackspace/objectstorage/v1/cdncontainers/delegate.go
+++ b/rackspace/objectstorage/v1/cdncontainers/delegate.go
@@ -1,6 +1,8 @@
package cdncontainers
import (
+ "strconv"
+
"github.com/rackspace/gophercloud"
os "github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers"
"github.com/rackspace/gophercloud/pagination"
@@ -58,7 +60,7 @@
if err != nil {
return nil, err
}
-
+ h["X-Cdn-Enabled"] = strconv.FormatBool(opts.CDNEnabled)
return h, nil
}