This repository was archived by the owner on Aug 1, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
openstack/compute/v2/servers Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 8
8
"fmt"
9
9
"testing"
10
10
11
+ "github.com/jrperritt/gophercloud/testhelper/client"
11
12
"github.com/rackspace/gophercloud"
12
13
th "github.com/rackspace/gophercloud/testhelper"
13
14
"golang.org/x/crypto/ssh"
@@ -97,3 +98,14 @@ KSde3I0ybDz7iS2EtceKB7m4C0slYd+oBkm4efuF00rCOKDwpFq45m0=
97
98
th .AssertNoErr (t , err )
98
99
th .AssertEquals (t , "ruZKK0tqxRfYm5t7lSJq" , pwd )
99
100
}
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
+ }
Original file line number Diff line number Diff line change @@ -138,6 +138,11 @@ func (p Pager) AllPages() (Page, error) {
138
138
// that type.
139
139
pageType := reflect .TypeOf (testPage )
140
140
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
+
141
146
// Switch on the page body type. Recognized types are `map[string]interface{}`,
142
147
// `[]byte`, and `[]interface{}`.
143
148
switch testPage .GetBody ().(type ) {
@@ -153,7 +158,14 @@ func (p Pager) AllPages() (Page, error) {
153
158
key = k
154
159
}
155
160
}
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
+ }
157
169
return true , nil
158
170
})
159
171
if err != nil {
You can’t perform that action at this time.
0 commit comments