unit tests for delegated functions; factor out common test http handlers into 'fixtures.go' files
diff --git a/rackspace/objectstorage/v1/accounts/delegate_test.go b/rackspace/objectstorage/v1/accounts/delegate_test.go
index f9c870a..15a21ae 100644
--- a/rackspace/objectstorage/v1/accounts/delegate_test.go
+++ b/rackspace/objectstorage/v1/accounts/delegate_test.go
@@ -2,14 +2,33 @@
import (
"testing"
- //th "github.com/rackspace/gophercloud/testhelper"
- //fake "github.com/rackspace/gophercloud/testhelper/client"
+
+ os "github.com/rackspace/gophercloud/openstack/objectstorage/v1/accounts"
+ th "github.com/rackspace/gophercloud/testhelper"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
)
func TestGetAccounts(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleGetAccountSuccessfully(t)
+ options := &UpdateOpts{Metadata: map[string]string{"gophercloud-test": "accounts"}}
+ _, err := Update(fake.ServiceClient(), options).ExtractHeaders()
+ if err != nil {
+ t.Fatalf("Unable to update account: %v", err)
+ }
}
func TestUpdateAccounts(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleUpdateAccountSuccessfully(t)
+ expected := map[string]string{"Foo": "bar"}
+ actual, err := Get(fake.ServiceClient()).ExtractMetadata()
+ if err != nil {
+ t.Fatalf("Unable to get account metadata: %v", err)
+ }
+ th.CheckDeepEquals(t, expected, actual)
}
diff --git a/rackspace/objectstorage/v1/containers/delegate.go b/rackspace/objectstorage/v1/containers/delegate.go
index 67c2c41..293cbf1 100644
--- a/rackspace/objectstorage/v1/containers/delegate.go
+++ b/rackspace/objectstorage/v1/containers/delegate.go
@@ -6,6 +6,18 @@
"github.com/rackspace/gophercloud/pagination"
)
+// ExtractInfo interprets a page of List results when full container info
+// is requested.
+func ExtractInfo(page pagination.Page) ([]os.Container, error) {
+ return os.ExtractInfo(page)
+}
+
+// ExtractNames interprets a page of List results when just the container
+// names are requested.
+func ExtractNames(page pagination.Page) ([]string, error) {
+ return os.ExtractNames(page)
+}
+
// List is a function that retrieves containers associated with the account as
// well as account metadata. It returns a pager which can be iterated with the
// EachPage function.
diff --git a/rackspace/objectstorage/v1/containers/delegate_test.go b/rackspace/objectstorage/v1/containers/delegate_test.go
index 0c09d3e..86868ae 100644
--- a/rackspace/objectstorage/v1/containers/delegate_test.go
+++ b/rackspace/objectstorage/v1/containers/delegate_test.go
@@ -1 +1,91 @@
package containers
+
+import (
+ "testing"
+
+ os "github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers"
+ "github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
+)
+
+func TestListContainerInfo(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleListContainerInfoSuccessfully(t)
+
+ count := 0
+ err := List(fake.ServiceClient(), &os.ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractInfo(page)
+ th.AssertNoErr(t, err)
+
+ th.CheckDeepEquals(t, os.ExpectedListInfo, actual)
+
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, count, 1)
+}
+
+func TestListContainerNames(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleListContainerNamesSuccessfully(t)
+
+ count := 0
+ err := List(fake.ServiceClient(), &os.ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractNames(page)
+ if err != nil {
+ t.Errorf("Failed to extract container names: %v", err)
+ return false, err
+ }
+
+ th.CheckDeepEquals(t, os.ExpectedListNames, actual)
+
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, count, 1)
+}
+
+func TestCreateContainers(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleCreateContainerSuccessfully(t)
+
+ options := os.CreateOpts{ContentType: "application/json", Metadata: map[string]string{"foo": "bar"}}
+ headers, err := Create(fake.ServiceClient(), "testContainer", options).ExtractHeaders()
+ th.CheckNoErr(t, err)
+ th.CheckEquals(t, "bar", headers["X-Container-Meta-Foo"][0])
+
+}
+
+func TestDeleteContainers(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleDeleteContainerSuccessfully(t)
+
+ _, err := Delete(fake.ServiceClient(), "testContainer").ExtractHeaders()
+ th.CheckNoErr(t, err)
+}
+
+func TestUpdateContainers(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleUpdateContainerSuccessfully(t)
+
+ options := &os.UpdateOpts{Metadata: map[string]string{"foo": "bar"}}
+ _, err := Update(fake.ServiceClient(), "testContainer", options).ExtractHeaders()
+ th.CheckNoErr(t, err)
+}
+
+func TestGetContainers(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleGetContainerSuccessfully(t)
+
+ _, err := Get(fake.ServiceClient(), "testContainer").ExtractMetadata()
+ th.CheckNoErr(t, err)
+}
diff --git a/rackspace/objectstorage/v1/objects/delegate_test.go b/rackspace/objectstorage/v1/objects/delegate_test.go
index 004cbf8..808f940 100644
--- a/rackspace/objectstorage/v1/objects/delegate_test.go
+++ b/rackspace/objectstorage/v1/objects/delegate_test.go
@@ -1 +1,115 @@
package objects
+
+import (
+ "bytes"
+ "testing"
+
+ os "github.com/rackspace/gophercloud/openstack/objectstorage/v1/objects"
+ "github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
+)
+
+func TestDownloadObject(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleDownloadObjectSuccessfully(t)
+
+ content, err := Download(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractContent()
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, string(content), "Successful download with Gophercloud")
+}
+
+func TestListObjectsInfo(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleListObjectsInfoSuccessfully(t)
+
+ count := 0
+ options := &os.ListOpts{Full: true}
+ err := List(fake.ServiceClient(), "testContainer", options).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractInfo(page)
+ th.AssertNoErr(t, err)
+
+ th.CheckDeepEquals(t, os.ExpectedListInfo, actual)
+
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, count, 1)
+}
+
+func TestListObjectNames(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleListObjectNamesSuccessfully(t)
+
+ count := 0
+ options := &os.ListOpts{Full: false}
+ err := List(fake.ServiceClient(), "testContainer", options).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractNames(page)
+ if err != nil {
+ t.Errorf("Failed to extract container names: %v", err)
+ return false, err
+ }
+
+ th.CheckDeepEquals(t, os.ExpectedListNames, actual)
+
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, count, 1)
+}
+
+func TestCreateObject(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleCreateObjectSuccessfully(t)
+
+ content := bytes.NewBufferString("Did gyre and gimble in the wabe")
+ options := &os.CreateOpts{ContentType: "application/json"}
+ _, err := Create(fake.ServiceClient(), "testContainer", "testObject", content, options).ExtractHeaders()
+ th.AssertNoErr(t, err)
+}
+
+func TestCopyObject(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleCopyObjectSuccessfully(t)
+
+ options := &CopyOpts{Destination: "/newTestContainer/newTestObject"}
+ _, err := Copy(fake.ServiceClient(), "testContainer", "testObject", options).ExtractHeaders()
+ th.AssertNoErr(t, err)
+}
+
+func TestDeleteObject(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleDeleteObjectSuccessfully(t)
+
+ _, err := Delete(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractHeaders()
+ th.AssertNoErr(t, err)
+}
+
+func TestUpdateObject(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleUpdateObjectSuccessfully(t)
+
+ options := &os.UpdateOpts{Metadata: map[string]string{"Gophercloud-Test": "objects"}}
+ _, err := Update(fake.ServiceClient(), "testContainer", "testObject", options).ExtractHeaders()
+ th.AssertNoErr(t, err)
+}
+
+func TestGetObject(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ os.HandleGetObjectSuccessfully(t)
+
+ expected := map[string]string{"Gophercloud-Test": "objects"}
+ actual, err := Get(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractMetadata()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, expected, actual)
+}