Skip to content
Snippets Groups Projects
Commit e8a751a7 authored by Danis Kirasirov's avatar Danis Kirasirov
Browse files

Добавлен тест для BatchProcessor

parent ce608c18
No related branches found
No related tags found
No related merge requests found
...@@ -31,3 +31,12 @@ func (d *DummyWithOptions) Find(_ context.Context, _, _, _ string, _ *Filter, op ...@@ -31,3 +31,12 @@ func (d *DummyWithOptions) Find(_ context.Context, _, _, _ string, _ *Filter, op
} }
return make([]*Item, limit), d.Total, nil 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
}
...@@ -34,19 +34,14 @@ func TestBatchProcessor(t *testing.T) { ...@@ -34,19 +34,14 @@ func TestBatchProcessor(t *testing.T) {
assert.Equal(t, 0, counter) 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} itemssvc := &DummyWithOptions{Items: nil, Total: 1000}
b := &BatchProcessor{ b := &BatchProcessor{
Items: itemssvc, Items: itemssvc,
SpaceID: "sp", SpaceID: "sp",
EnvID: environments.DefaultEnvironment, EnvID: environments.DefaultEnvironment,
CollectionID: "col", CollectionID: "col",
FindOptions: &FindOptions{ FindOptions: &FindOptions{FindOptions: *options.New(0, 25)},
Regular: true,
Hidden: true,
Templates: true,
FindOptions: *options.New(0, 25),
},
} }
var counter int var counter int
...@@ -54,4 +49,20 @@ func TestBatchProcessor(t *testing.T) { ...@@ -54,4 +49,20 @@ func TestBatchProcessor(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, 1000/25, counter) 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)
})
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment