forked from grafana/pyroscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_test.go
39 lines (33 loc) · 1.13 KB
/
batch_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package iter
import (
"context"
"errors"
"testing"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
)
func TestReadBatch(t *testing.T) {
ctx := context.Background()
require.Error(t, ReadBatch(ctx, NewSliceIterator(lo.Times(20, func(i int) int { return i })), 10,
func(context.Context, []int) error {
return errors.New("foo")
}))
var batches [][]int
require.NoError(t, ReadBatch(ctx, NewSliceIterator(lo.Times(20, func(i int) int { return i })), 10,
func(_ context.Context, batch []int) error {
c := make([]int, len(batch))
copy(c, batch)
batches = append(batches, c)
return nil
}))
require.Equal(t, [][]int{lo.Times(10, func(i int) int { return i }), lo.Times(10, func(i int) int { return 10 + i })}, batches)
batches = nil
require.NoError(t, ReadBatch(ctx, NewSliceIterator(lo.Times(20, func(i int) int { return i })), 11,
func(_ context.Context, batch []int) error {
c := make([]int, len(batch))
copy(c, batch)
batches = append(batches, c)
return nil
}))
require.Equal(t, [][]int{lo.Times(11, func(i int) int { return i }), lo.Times(9, func(i int) int { return 11 + i })}, batches)
}