Skip to content

Commit a113e46

Browse files
authored
keystone: add support for per page limit
1 parent 49cdcd6 commit a113e46

4 files changed

Lines changed: 51 additions & 5 deletions

File tree

openstack/identity/v3/domains/requests.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ type ListOpts struct {
2020

2121
// Name filters the response by domain name.
2222
Name string `q:"name"`
23+
24+
// Limit limits the number of projects returned per page.
25+
Limit int `q:"limit"`
2326
}
2427

2528
// ToDomainListQuery formats a ListOpts into a query string.

openstack/identity/v3/projects/requests.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ type ListOpts struct {
4545
// NotTagsAny filters on specific project tags. At least one of the tags must be absent for the project.
4646
NotTagsAny string `q:"not-tags-any"`
4747

48+
// Limit limits the number of projects returned per page.
49+
Limit int `q:"limit"`
50+
4851
// Filters filters the response by custom filters such as
4952
// 'name__contains=foo'
5053
Filters map[string]string `q:"-"`

openstack/identity/v3/projects/testing/fixtures_test.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,19 @@ const ListOutput = `
5959
"parent_id": null,
6060
"tags": ["Red", "Team"],
6161
"test": "old"
62-
},
62+
}
63+
],
64+
"links": {
65+
"next": "%sprojects?limit=1&marker=1234",
66+
"self": "%sprojects?limit=1",
67+
"previous": null
68+
}
69+
}
70+
`
71+
72+
const ListOutputSecondPage = `
73+
{
74+
"projects": [
6375
{
6476
"is_domain": false,
6577
"description": "The team that is blue",
@@ -73,8 +85,21 @@ const ListOutput = `
7385
}
7486
}
7587
],
88+
"links": {
89+
"next": "%sprojects?limit=1&marker=9876",
90+
"self": "%sprojects?limit=1&marker=1234",
91+
"previous": null
92+
}
93+
}
94+
`
95+
96+
const ListOutputThirdPage = `
97+
{
98+
"projects": [
99+
],
76100
"links": {
77101
"next": null,
102+
"self": "%sprojects?limit=1&marker=9876",
78103
"previous": null
79104
}
80105
}
@@ -299,7 +324,15 @@ func HandleListProjectsSuccessfully(t *testing.T, fakeServer th.FakeServer) {
299324

300325
w.Header().Set("Content-Type", "application/json")
301326
w.WriteHeader(http.StatusOK)
302-
fmt.Fprint(w, ListOutput)
327+
328+
switch r.URL.Query().Get("marker") {
329+
case "":
330+
fmt.Fprintf(w, ListOutput, fakeServer.Endpoint(), fakeServer.Endpoint())
331+
case "1234":
332+
fmt.Fprintf(w, ListOutputSecondPage, fakeServer.Endpoint(), fakeServer.Endpoint())
333+
case "9876":
334+
fmt.Fprintf(w, ListOutputThirdPage, fakeServer.Endpoint())
335+
}
303336
})
304337
}
305338

openstack/identity/v3/projects/testing/requests_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,26 @@ func TestListProjects(t *testing.T) {
3535
defer fakeServer.Teardown()
3636
HandleListProjectsSuccessfully(t, fakeServer)
3737

38+
actualProjects := make([]projects.Project, 0, 2)
3839
count := 0
39-
err := projects.List(client.ServiceClient(fakeServer), nil).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
40+
opts := projects.ListOpts{
41+
Limit: 1,
42+
}
43+
err := projects.List(client.ServiceClient(fakeServer), opts).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
4044
count++
4145

4246
actual, err := projects.ExtractProjects(page)
4347
th.AssertNoErr(t, err)
4448

45-
th.CheckDeepEquals(t, ExpectedProjectSlice, actual)
49+
actualProjects = append(actualProjects, actual...)
4650

4751
return true, nil
4852
})
4953
th.AssertNoErr(t, err)
50-
th.CheckEquals(t, count, 1)
54+
th.CheckEquals(t, count, 2)
55+
56+
th.CheckEquals(t, len(actualProjects), 2)
57+
th.CheckDeepEquals(t, ExpectedProjectSlice, actualProjects)
5158
}
5259

5360
func TestListGroupsFiltersCheck(t *testing.T) {

0 commit comments

Comments
 (0)