use gophercloud.ExtractInto*Ptr for ExtractInto and ^CtractVolumesInto
diff --git a/openstack/blockstorage/v2/volumes/results.go b/openstack/blockstorage/v2/volumes/results.go
index f00cfe8..1208e10 100644
--- a/openstack/blockstorage/v2/volumes/results.go
+++ b/openstack/blockstorage/v2/volumes/results.go
@@ -1,10 +1,6 @@
package volumes
import (
- "encoding/json"
- "fmt"
- "reflect"
-
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
@@ -105,28 +101,11 @@
}
func (r commonResult) ExtractInto(v interface{}) error {
- t := reflect.TypeOf(v)
- if k := t.Kind(); k != reflect.Ptr {
- return fmt.Errorf("Expected pointer to struct, got %v", k)
- }
- t = t.Elem()
- if k := t.Kind(); k != reflect.Struct {
- return fmt.Errorf("Expected pointer to struct, got %v", k)
- }
+ return r.Result.ExtractIntoStructPtr(v, "volume")
+}
- var vol map[string]map[string]interface{}
- err := r.Result.ExtractInto(&vol)
- if err != nil {
- return err
- }
-
- b, err := json.Marshal(vol["volume"])
- if err != nil {
- return err
- }
-
- err = json.Unmarshal(b, &v)
- return err
+func ExtractVolumesInto(r pagination.Page, v interface{}) error {
+ return r.(VolumePage).Result.ExtractIntoSlicePtr(v, "volumes")
}
// CreateResult contains the response body and error from a Create request.
diff --git a/openstack/blockstorage/v2/volumes/testing/requests_test.go b/openstack/blockstorage/v2/volumes/testing/requests_test.go
index b723e58..0385e50 100644
--- a/openstack/blockstorage/v2/volumes/testing/requests_test.go
+++ b/openstack/blockstorage/v2/volumes/testing/requests_test.go
@@ -12,7 +12,7 @@
"github.com/gophercloud/gophercloud/testhelper/client"
)
-func TestList(t *testing.T) {
+func TestListWithExtensions(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
@@ -95,6 +95,30 @@
}
}
+func TestListAllWithExtensions(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockListResponse(t)
+
+ type VolumeWithExt struct {
+ volumes.Volume
+ tenantattr.VolumeExt
+ }
+
+ allPages, err := volumes.List(client.ServiceClient(), &volumes.ListOpts{}).AllPages()
+ th.AssertNoErr(t, err)
+
+ var actual []struct {
+ volumes.Volume
+ tenantattr.VolumeExt
+ }
+ err = volumes.ExtractVolumesInto(allPages, &actual)
+ th.AssertNoErr(t, err)
+ th.AssertEquals(t, 2, len(actual))
+ th.AssertEquals(t, "304dc00909ac4d0da6c62d816bcb3459", actual[0].TenantID)
+}
+
func TestListAll(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()