Adding delegate tests for volumes
diff --git a/rackspace/blockstorage/v1/volumes/delegate.go b/rackspace/blockstorage/v1/volumes/delegate.go
index 4372f2b..a0b2380 100644
--- a/rackspace/blockstorage/v1/volumes/delegate.go
+++ b/rackspace/blockstorage/v1/volumes/delegate.go
@@ -6,13 +6,6 @@
"github.com/rackspace/gophercloud/pagination"
)
-// CreateOpts contains options for creating a Volume. This object is passed to
-// the volumes.Create function. For more information about these parameters,
-// see the Volume object.
-type CreateOpts struct {
- os.CreateOpts
-}
-
// Create will create a new Volume based on the values in CreateOpts. To extract
// the Volume object from the response, call the Extract method on the
// CreateResult.
diff --git a/rackspace/blockstorage/v1/volumes/delegate_test.go b/rackspace/blockstorage/v1/volumes/delegate_test.go
index bea59b2..3c50d21 100644
--- a/rackspace/blockstorage/v1/volumes/delegate_test.go
+++ b/rackspace/blockstorage/v1/volumes/delegate_test.go
@@ -1 +1,96 @@
package volumes
+
+import (
+ "testing"
+
+ os "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
+ "github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
+)
+
+func TestList(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ os.MockListResponse(t)
+
+ count := 0
+
+ List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := ExtractVolumes(page)
+ if err != nil {
+ t.Errorf("Failed to extract volumes: %v", err)
+ return false, err
+ }
+
+ expected := []Volume{
+ Volume{
+ ID: "289da7f8-6440-407c-9fb4-7db01ec49164",
+ Name: "vol-001",
+ },
+ Volume{
+ ID: "96c3bda7-c82a-4f50-be73-ca7621794835",
+ Name: "vol-002",
+ },
+ }
+
+ th.CheckDeepEquals(t, expected, actual)
+
+ return true, nil
+ })
+
+ if count != 1 {
+ t.Errorf("Expected 1 page, got %d", count)
+ }
+}
+
+func TestGet(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ os.MockGetResponse(t)
+
+ v, err := Get(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
+ th.AssertNoErr(t, err)
+
+ th.AssertEquals(t, v.Name, "vol-001")
+ th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+}
+
+func TestCreate(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ os.MockCreateResponse(t)
+
+ options := os.CreateOpts{Size: 4}
+ n, err := Create(fake.ServiceClient(), options).Extract()
+ th.AssertNoErr(t, err)
+
+ th.AssertEquals(t, n.Size, 4)
+ th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+}
+
+func TestDelete(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ os.MockDeleteResponse(t)
+
+ err := Delete(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+ th.AssertNoErr(t, err)
+}
+
+func TestUpdate(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ os.MockUpdateResponse(t)
+
+ options := &UpdateOpts{Name: "vol-002"}
+ v, err := Update(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract()
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, "vol-002", v.Name)
+}
diff --git a/rackspace/blockstorage/v1/volumes/results.go b/rackspace/blockstorage/v1/volumes/results.go
index 8c3f837..cec41e0 100644
--- a/rackspace/blockstorage/v1/volumes/results.go
+++ b/rackspace/blockstorage/v1/volumes/results.go
@@ -8,12 +8,10 @@
"github.com/mitchellh/mapstructure"
)
-type Volume struct {
- os.Volume
-}
+type Volume os.Volume
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// CreateResult represents the result of a create operation
@@ -31,7 +29,7 @@
os.UpdateResult
}
-func commonExtract(resp map[string]interface{}, err error) (*Volume, error) {
+func commonExtract(resp interface{}, err error) (*Volume, error) {
if err != nil {
return nil, err
}
@@ -47,17 +45,17 @@
// Extract will get the Volume object out of the GetResult object.
func (r GetResult) Extract() (*Volume, error) {
- return commonExtract(r.Resp, r.Err)
+ return commonExtract(r.Body, r.Err)
}
// Extract will get the Volume object out of the CreateResult object.
func (r CreateResult) Extract() (*Volume, error) {
- return commonExtract(r.Resp, r.Err)
+ return commonExtract(r.Body, r.Err)
}
// Extract will get the Volume object out of the UpdateResult object.
func (r UpdateResult) Extract() (*Volume, error) {
- return commonExtract(r.Resp, r.Err)
+ return commonExtract(r.Body, r.Err)
}
// ExtractSnapshots extracts and returns Volumes. It is used while iterating over a volumes.List call.