Skip to content

Commit

Permalink
fix pagination size 0 (#1479)
Browse files Browse the repository at this point in the history
* fix pagination size 0
  • Loading branch information
SimoneDutto authored Dec 4, 2024
1 parent ba1f73a commit 55d9bc9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/common/pagination/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions internal/common/pagination/pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions internal/jimmhttp/rebac_admin/resources_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 55d9bc9

Please sign in to comment.