-
Notifications
You must be signed in to change notification settings - Fork 17
/
raw_output_test.go
80 lines (65 loc) · 1.75 KB
/
raw_output_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package baker_test
import (
"strings"
"testing"
"github.com/AdRoll/baker"
"github.com/AdRoll/baker/input/inputtest"
"github.com/AdRoll/baker/output/outputtest"
)
func TestRawOutputFields(t *testing.T) {
toml := `
[fields]
names=["field0", "field1", "field2", "field3"]
[input]
name="Records"
[output]
name="Recorder"
procs=1
fields=["field2", "field0", "field1", "field3"]
`
c := baker.Components{
Inputs: []baker.InputDesc{inputtest.RecordsDesc},
Outputs: []baker.OutputDesc{outputtest.RecorderDesc},
}
cfg, err := baker.NewConfigFromToml(strings.NewReader(toml), c)
if err != nil {
t.Fatal(err)
}
topology, err := baker.NewTopologyFromConfig(cfg)
if err != nil {
t.Fatal(err)
}
in := topology.Input.(*inputtest.Records)
out := topology.Output[0].(*outputtest.Recorder)
for i := 0; i < 10; i++ {
ll := baker.LogLine{FieldSeparator: baker.DefaultLogLineFieldSeparator}
ll.Set(0, []byte("value0"))
ll.Set(1, []byte("value1"))
ll.Set(3, []byte("value3"))
in.Records = append(in.Records, &ll)
}
topology.Start()
topology.Wait()
if len(out.Records) != 10 {
t.Fatalf("number of records and set of fields should be 3, got %d", len(out.Records))
}
for _, lldata := range out.Records {
// lldata.Fields keep the same order as in output.fields (in TOML)
fields := lldata.Fields
if fields[0] != "" {
t.Errorf("got fields[0] = %q, want %q", fields[0], "")
}
if fields[1] != "value0" {
t.Errorf("got fields[1] = %q, want %q", fields[1], "value0")
}
if fields[2] != "value1" {
t.Errorf("got fields[2] = %q, want %q", fields[2], "value2")
}
if fields[3] != "value3" {
t.Errorf("got fields[3] = %q, want %q", fields[3], "value3")
}
if len(fields) != 4 {
t.Errorf("got %d fields, want %d", len(fields), 4)
}
}
}