return from AllPages for SinglePageBase
diff --git a/openstack/compute/v2/servers/results_test.go b/openstack/compute/v2/servers/results_test.go
index 2dba484..fa94dba 100644
--- a/openstack/compute/v2/servers/results_test.go
+++ b/openstack/compute/v2/servers/results_test.go
@@ -8,6 +8,7 @@
"fmt"
"testing"
+ "github.com/jrperritt/gophercloud/testhelper/client"
"github.com/rackspace/gophercloud"
th "github.com/rackspace/gophercloud/testhelper"
"golang.org/x/crypto/ssh"
@@ -97,3 +98,14 @@
th.AssertNoErr(t, err)
th.AssertEquals(t, "ruZKK0tqxRfYm5t7lSJq", pwd)
}
+
+func TestListAddressesAllPages(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleAddressListSuccessfully(t)
+
+ allPages, err := ListAddresses(client.ServiceClient(), "asdfasdfasdf").AllPages()
+ th.AssertNoErr(t, err)
+ _, err = ExtractAddresses(allPages)
+ th.AssertNoErr(t, err)
+}
diff --git a/pagination/pager.go b/pagination/pager.go
index a7593ac..6f1ca04 100644
--- a/pagination/pager.go
+++ b/pagination/pager.go
@@ -138,6 +138,11 @@
// that type.
pageType := reflect.TypeOf(testPage)
+ // if it's a single page, just return the testPage (first page)
+ if _, found := pageType.FieldByName("SinglePageBase"); found {
+ return testPage, nil
+ }
+
// Switch on the page body type. Recognized types are `map[string]interface{}`,
// `[]byte`, and `[]interface{}`.
switch testPage.GetBody().(type) {
@@ -153,7 +158,14 @@
key = k
}
}
- pagesSlice = append(pagesSlice, b[key].([]interface{})...)
+ switch keyType := b[key].(type) {
+ case map[string]interface{}:
+ pagesSlice = append(pagesSlice, keyType)
+ case []interface{}:
+ pagesSlice = append(pagesSlice, b[key].([]interface{})...)
+ default:
+ return false, fmt.Errorf("Unsupported page body type: %+v", keyType)
+ }
return true, nil
})
if err != nil {