Skip to content

Commit

Permalink
fix(api): dataplane overview pagination (#7803)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com>
  • Loading branch information
jakubdyszkiewicz authored Sep 20, 2023
1 parent 26f277b commit 33d5982
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 0 additions & 2 deletions pkg/api-server/dataplane_overview_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ func (r *dataplaneOverviewEndpoints) inspectDataplanes(request *restful.Request,
return
}

// pagination is not supported yet so we need to override pagination total items after retaining dataplanes
overviews.GetPagination().SetTotal(uint32(len(overviews.Items)))
restList := rest.From.ResourceList(&overviews)
restList.Next = nextLink(request, overviews.GetPagination().NextOffset)
if err := response.WriteAsJson(restList); err != nil {
Expand Down
12 changes: 12 additions & 0 deletions pkg/api-server/dataplane_overview_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,17 @@ var _ = Describe("Dataplane Overview Endpoints", func() {
expectedJson: fmt.Sprintf(`{"total": 2, "items": [%s, %s], "next": null}`, gatewayBuiltinJson, gatewayDelegatedJson),
}),
)

It("should paginate correctly", func() {
// when
response, err := http.Get("http://" + apiServer.Address() + "/meshes/mesh1/dataplanes+insights?size=1")
Expect(err).ToNot(HaveOccurred())

// then
Expect(response.StatusCode).To(Equal(200))
body, err := io.ReadAll(response.Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(body)).To(MatchJSON(fmt.Sprintf(`{"total": 3, "items": [%s], "next": "http://%s/meshes/mesh1/dataplanes+insights?offset=1&size=1"}`, dp1Json, apiServer.Address())))
})
})
})

0 comments on commit 33d5982

Please sign in to comment.