Permalink
Browse files

return from AllPages for SinglePageBase

  • Loading branch information...
1 parent 231898e commit 057373d0ce19a917a0afc29e93e82e95c1533535 @jrperritt jrperritt committed May 2, 2016
Showing with 25 additions and 1 deletion.
  1. +12 −0 openstack/compute/v2/servers/results_test.go
  2. +13 −1 pagination/pager.go
@@ -8,6 +8,7 @@ import (
"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 @@ KSde3I0ybDz7iS2EtceKB7m4C0slYd+oBkm4efuF00rCOKDwpFq45m0=
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)
+}
View
@@ -138,6 +138,11 @@ func (p Pager) AllPages() (Page, error) {
// 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 @@ func (p Pager) AllPages() (Page, error) {
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 {

0 comments on commit 057373d

Please sign in to comment.