From 55d9bc983e5984de082af6b33de58fc72453e9e7 Mon Sep 17 00:00:00 2001 From: SimoneDutto Date: Wed, 4 Dec 2024 15:53:07 +0100 Subject: [PATCH] fix pagination size 0 (#1479) * fix pagination size 0 --- internal/common/pagination/pagination.go | 2 +- internal/common/pagination/pagination_test.go | 7 +++++++ .../rebac_admin/resources_integration_test.go | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/internal/common/pagination/pagination.go b/internal/common/pagination/pagination.go index 5b05db6ff..c0d562687 100644 --- a/internal/common/pagination/pagination.go +++ b/internal/common/pagination/pagination.go @@ -20,7 +20,7 @@ type LimitOffsetPagination struct { // NewOffsetFilter creates a filter for limit/offset pagination. // If limit or offset are out of bounds, defaults will be used instead. func NewOffsetFilter(limit int, offset int) LimitOffsetPagination { - if limit < 0 { + if limit <= 0 { limit = defaultOffsetFilterPageSize } if limit > maxOffsetFilterPageSize { diff --git a/internal/common/pagination/pagination_test.go b/internal/common/pagination/pagination_test.go index 518605215..a44ee4bed 100644 --- a/internal/common/pagination/pagination_test.go +++ b/internal/common/pagination/pagination_test.go @@ -26,6 +26,13 @@ func TestOffsetFilter(t *testing.T) { wantLimit: 10, wantOffset: 5, }, + { + desc: "Valid value are not changed", + limit: 0, + offset: 0, + wantLimit: pagination.DefaultPageSize, + wantOffset: 0, + }, { desc: "Negative values are corrected", limit: -1, diff --git a/internal/jimmhttp/rebac_admin/resources_integration_test.go b/internal/jimmhttp/rebac_admin/resources_integration_test.go index 0d0dd2908..6fbec602a 100644 --- a/internal/jimmhttp/rebac_admin/resources_integration_test.go +++ b/internal/jimmhttp/rebac_admin/resources_integration_test.go @@ -111,6 +111,19 @@ func (s *resourcesSuite) TestListResources(c *gc.C) { wantNextpage *int ids []testEntity }{ + { + desc: "test default sizes", + wantPage: 0, + wantSize: 5, + ids: ids, + }, + { + desc: "test default sizes", + page: utils.IntToPointer(0), + wantPage: 0, + wantSize: 5, + ids: ids, + }, { desc: "test with first page", size: utils.IntToPointer(2),