From e8a751a7f575d74e5be4ce0c3757403e7b8d6548 Mon Sep 17 00:00:00 2001 From: Danis Kirasirov <dbgbbu@gmail.com> Date: Thu, 15 Feb 2024 16:49:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20=D0=B4=D0=BB=D1=8F=20BatchP?= =?UTF-8?q?rocessor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/items/dummy.go | 9 +++++++++ pkg/items/pagination_test.go | 25 ++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/pkg/items/dummy.go b/pkg/items/dummy.go index 082f5c1f..a31b47c7 100644 --- a/pkg/items/dummy.go +++ b/pkg/items/dummy.go @@ -31,3 +31,12 @@ func (d *DummyWithOptions) Find(_ context.Context, _, _, _ string, _ *Filter, op } return make([]*Item, limit), d.Total, nil } + +func (d *DummyWithOptions) FindPublished(_ context.Context, _, _, _ string, _ *Filter, opts ...*FindPublishedOptions) ([]*Item, int, error) { + fo := MergeFindPublishedOptions(opts...) + limit := fo.Limit + if limit == 0 { + limit = fo.PageSize + } + return make([]*Item, limit), d.Total, nil +} diff --git a/pkg/items/pagination_test.go b/pkg/items/pagination_test.go index c0985d33..6f36fc6d 100644 --- a/pkg/items/pagination_test.go +++ b/pkg/items/pagination_test.go @@ -34,19 +34,14 @@ func TestBatchProcessor(t *testing.T) { assert.Equal(t, 0, counter) }) - t.Run("Success", func(t *testing.T) { + t.Run("With FindOptions", func(t *testing.T) { itemssvc := &DummyWithOptions{Items: nil, Total: 1000} b := &BatchProcessor{ Items: itemssvc, SpaceID: "sp", EnvID: environments.DefaultEnvironment, CollectionID: "col", - FindOptions: &FindOptions{ - Regular: true, - Hidden: true, - Templates: true, - FindOptions: *options.New(0, 25), - }, + FindOptions: &FindOptions{FindOptions: *options.New(0, 25)}, } var counter int @@ -54,4 +49,20 @@ func TestBatchProcessor(t *testing.T) { require.NoError(t, err) assert.Equal(t, 1000/25, counter) }) + + t.Run("With FindPublishedOptions", func(t *testing.T) { + itemssvc := &DummyWithOptions{Items: nil, Total: 60} + b := &BatchProcessor{ + Items: itemssvc, + SpaceID: "sp", + EnvID: environments.DefaultEnvironment, + CollectionID: "col", + FindPublishedOptions: &FindPublishedOptions{FindOptions: *options.New(0, 20)}, + } + + var counter int + _, err := b.Do(context.Background(), func(batch []*Item) error { counter++; return nil }) + require.NoError(t, err) + assert.Equal(t, 60/20, counter) + }) } -- GitLab