Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit d62a69f

Browse files
committed
Merge pull request #567 from jrperritt/list-addresses-all-pages-bug-fix
[rfr] return from AllPages for SinglePageBase
2 parents c54bbac + 42b019f commit d62a69f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

openstack/compute/v2/servers/results_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/rackspace/gophercloud"
1212
th "github.com/rackspace/gophercloud/testhelper"
13+
"github.com/rackspace/gophercloud/testhelper/client"
1314
"golang.org/x/crypto/ssh"
1415
)
1516

@@ -97,3 +98,14 @@ KSde3I0ybDz7iS2EtceKB7m4C0slYd+oBkm4efuF00rCOKDwpFq45m0=
9798
th.AssertNoErr(t, err)
9899
th.AssertEquals(t, "ruZKK0tqxRfYm5t7lSJq", pwd)
99100
}
101+
102+
func TestListAddressesAllPages(t *testing.T) {
103+
th.SetupHTTP()
104+
defer th.TeardownHTTP()
105+
HandleAddressListSuccessfully(t)
106+
107+
allPages, err := ListAddresses(client.ServiceClient(), "asdfasdfasdf").AllPages()
108+
th.AssertNoErr(t, err)
109+
_, err = ExtractAddresses(allPages)
110+
th.AssertNoErr(t, err)
111+
}

pagination/pager.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ func (p Pager) AllPages() (Page, error) {
138138
// that type.
139139
pageType := reflect.TypeOf(testPage)
140140

141+
// if it's a single page, just return the testPage (first page)
142+
if _, found := pageType.FieldByName("SinglePageBase"); found {
143+
return testPage, nil
144+
}
145+
141146
// Switch on the page body type. Recognized types are `map[string]interface{}`,
142147
// `[]byte`, and `[]interface{}`.
143148
switch testPage.GetBody().(type) {
@@ -153,7 +158,14 @@ func (p Pager) AllPages() (Page, error) {
153158
key = k
154159
}
155160
}
156-
pagesSlice = append(pagesSlice, b[key].([]interface{})...)
161+
switch keyType := b[key].(type) {
162+
case map[string]interface{}:
163+
pagesSlice = append(pagesSlice, keyType)
164+
case []interface{}:
165+
pagesSlice = append(pagesSlice, b[key].([]interface{})...)
166+
default:
167+
return false, fmt.Errorf("Unsupported page body type: %+v", keyType)
168+
}
157169
return true, nil
158170
})
159171
if err != nil {

0 commit comments

Comments
 (0)