aboutsummaryrefslogtreecommitdiff
path: root/bundler/bundler_test.go
blob: bec12d0f397c00cda22ca60efa30eb533fd4fb1d (plain)
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
package bundler

import (
	"context"
	"testing"
)

func TestBundler(t *testing.T) {
	input := []int{1, 2, 3, 4}
	done := false
	b := New[int](func(_ context.Context, data []int) {
		if len(data) != 4 {
			t.Errorf("Wanted len(data) == %d, got: %d", len(input), len(data))
		}

		sum := 0
		const wantSum = 10
		for _, i := range data {
			sum += i
		}

		if sum != wantSum {
			t.Errorf("wanted sum of inputs to be %d, got: %d", wantSum, sum)
		}
		done = true
	})

	for _, i := range input {
		b.Add(i, 1)
	}

	b.Flush()

	if !done {
		t.Fatal("function wasn't called")
	}
}