aboutsummaryrefslogtreecommitdiffstats
path: root/skate/zipkey/batch_test.go
blob: 7c6a48cb4f3e66c8f05f2565fe560a46e185507a (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
package zipkey

import (
	"bytes"
	"encoding/json"
	"strings"
	"testing"
)

func TestBatcher(t *testing.T) {
	var (
		buf bytes.Buffer
		enc = json.NewEncoder(&buf)
		f   = func(g *Group) error {
			return enc.Encode(g)
		}
		b = NewBatcher(groupFunc(f))
	)
	b.GroupFunc(&Group{
		Key: "K1",
		G0:  []string{"A"},
		G1:  []string{"B"},
	})
	b.Close()
	var (
		got  = strings.TrimSpace(buf.String())
		want = `{"Key":"K1","G0":["A"],"G1":["B"]}`
	)
	if got != want {
		t.Fatalf("got %v, want %v", got, want)
	}
}