From 91f4ffba309be56374235de303455f35273328d3 Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Wed, 16 Jan 2019 17:51:07 +0100 Subject: [PATCH] chore: bucket pagination improvements --- bolt/bucket.go | 2 +- testing/bucket_service.go | 30 ++++++++++-------------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/bolt/bucket.go b/bolt/bucket.go index f5d393b528..75f8f48000 100644 --- a/bolt/bucket.go +++ b/bolt/bucket.go @@ -298,7 +298,7 @@ func (c *Client) findBuckets(ctx context.Context, tx *bolt.Tx, filter platform.B if count >= offset { bs = append(bs, b) } - count += 1 + count++ } if limit > 0 && len(bs) >= limit { diff --git a/testing/bucket_service.go b/testing/bucket_service.go index f9a283f412..482888883d 100644 --- a/testing/bucket_service.go +++ b/testing/bucket_service.go @@ -512,10 +512,7 @@ func FindBuckets( name string organization string organizationID platform.ID - - offset int - limit int - descending bool + findOptions platform.FindOptions } type wants struct { @@ -600,8 +597,10 @@ func FindBuckets( }, }, args: args{ - offset: 1, - limit: 1, + findOptions: platform.FindOptions{ + Offset: 1, + Limit: 1, + }, }, wants: wants{ buckets: []*platform.Bucket{ @@ -642,8 +641,10 @@ func FindBuckets( }, }, args: args{ - offset: 1, - descending: true, + findOptions: platform.FindOptions{ + Offset: 1, + Descending: true, + }, }, wants: wants{ buckets: []*platform.Bucket{ @@ -838,18 +839,7 @@ func FindBuckets( filter.Name = &tt.args.name } - opt := platform.FindOptions{} - if tt.args.offset > 0 { - opt.Offset = tt.args.offset - } - if tt.args.limit > 0 { - opt.Limit = tt.args.limit - } - if tt.args.descending { - opt.Descending = tt.args.descending - } - - buckets, _, err := s.FindBuckets(ctx, filter, opt) + buckets, _, err := s.FindBuckets(ctx, filter, tt.args.findOptions) diffPlatformErrors(tt.name, err, tt.wants.err, opPrefix, t) if diff := cmp.Diff(buckets, tt.wants.buckets, bucketCmpOptions...); diff != "" {