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) } }