-
Notifications
You must be signed in to change notification settings - Fork 17
/
desc_test.go
105 lines (93 loc) · 2.39 KB
/
desc_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package baker_test
import (
"strings"
"testing"
"github.com/AdRoll/baker"
"github.com/AdRoll/baker/filter/filtertest"
"github.com/AdRoll/baker/input/inputtest"
"github.com/AdRoll/baker/output/outputtest"
"github.com/AdRoll/baker/upload/uploadtest"
)
func checkDecodedConfig(t *testing.T, dcfg interface{}) {
t.Helper()
if dcfg == nil {
t.Errorf("DecodedConfig is nil, want struct{}{}")
}
_, ok := dcfg.(*struct{})
if !ok {
t.Errorf("config cast error")
}
}
func TestCompDescEmptyConfig(t *testing.T) {
dummyInputDesc := baker.InputDesc{
Name: "dummyInput",
New: func(cfg baker.InputParams) (baker.Input, error) {
checkDecodedConfig(t, cfg.DecodedConfig)
return inputtest.Base{}, nil
},
Config: &struct{}{},
}
dummyFilterDesc := baker.FilterDesc{
Name: "dummyFilter",
New: func(cfg baker.FilterParams) (baker.Filter, error) {
checkDecodedConfig(t, cfg.DecodedConfig)
return filtertest.Base{}, nil
},
Config: &struct{}{},
}
dummyOutputDesc := baker.OutputDesc{
Name: "dummyOutput",
New: func(cfg baker.OutputParams) (baker.Output, error) {
checkDecodedConfig(t, cfg.DecodedConfig)
return outputtest.Base{}, nil
},
Config: &struct{}{},
}
dummyUploadDesc := baker.UploadDesc{
Name: "dummyUpload",
New: func(cfg baker.UploadParams) (baker.Upload, error) {
checkDecodedConfig(t, cfg.DecodedConfig)
return uploadtest.Base{}, nil
},
Config: &struct{}{},
}
dummyMetricsDesc := baker.MetricsDesc{
Name: "dummyMetric",
New: func(cfg interface{}) (baker.MetricsClient, error) {
checkDecodedConfig(t, cfg)
return baker.NopMetrics{}, nil
},
Config: &struct{}{},
}
toml := `
[fields]
names = ["field0", "field1", "field2", "field3"]
[input]
name = "dummyInput"
[[filter]]
name = "dummyFilter"
[output]
name = "dummyOutput"
procs = 1
fields = ["field2", "field0", "field1", "field3"]
[upload]
name = "dummyUpload"
[metrics]
name = "dummyMetric"
`
comp := baker.Components{
Inputs: []baker.InputDesc{dummyInputDesc},
Filters: []baker.FilterDesc{dummyFilterDesc},
Outputs: []baker.OutputDesc{dummyOutputDesc},
Uploads: []baker.UploadDesc{dummyUploadDesc},
Metrics: []baker.MetricsDesc{dummyMetricsDesc},
}
cfg, err := baker.NewConfigFromToml(strings.NewReader(toml), comp)
if err != nil {
t.Fatalf("cannot parse config: %v", err)
}
_, err = baker.NewTopologyFromConfig(cfg)
if err != nil {
t.Fatalf("cannot build topology: %v", err)
}
}