forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters_runner_test.go
128 lines (114 loc) · 2.33 KB
/
filters_runner_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"packetbeat/filters"
"packetbeat/filters/nop"
"testing"
"github.com/stretchr/testify/assert"
)
func loadPlugins() {
filters.Filters.Register(filters.NopFilter, new(nop.Nop))
}
func TestLoadConfiguredFilters(t *testing.T) {
loadPlugins()
type o struct {
Name string
Type filters.Filter
}
type io struct {
Input map[string]interface{}
Output []o
}
tests := []io{
// should find configuration by types
io{
Input: map[string]interface{}{
"filters": []interface{}{"nop1", "nop2"},
"nop1": map[string]interface{}{
"type": "nop",
},
"nop2": map[string]interface{}{
"type": "nop",
},
},
Output: []o{
o{
Name: "nop1",
Type: filters.NopFilter,
},
o{
Name: "nop2",
Type: filters.NopFilter,
},
},
},
// should work with implicit configuration by name
io{
Input: map[string]interface{}{
"filters": []interface{}{"nop", "sample1"},
"sample1": map[string]interface{}{
"type": "nop",
},
},
Output: []o{
o{
Name: "nop",
Type: filters.NopFilter,
},
o{
Name: "sample1",
Type: filters.NopFilter,
},
},
},
}
for _, test := range tests {
res, err := LoadConfiguredFilters(test.Input)
assert.Nil(t, err)
res_o := []o{}
for _, r := range res {
res_o = append(res_o, o{Name: r.String(), Type: r.Type()})
}
assert.Equal(t, test.Output, res_o)
}
}
func TestLoadConfiguredFiltersNegative(t *testing.T) {
loadPlugins()
type io struct {
Input map[string]interface{}
Err string
}
tests := []io{
io{
Input: map[string]interface{}{
"filters": []interface{}{"nop1", "nop2"},
"nop1": map[string]interface{}{
"type": "nop",
},
},
Err: "No such filter type and no corresponding configuration: nop2",
},
io{
Input: map[string]interface{}{
"filters": []interface{}{"nop1", "nop"},
"nop1": map[string]interface{}{
"hype": "nop",
},
},
Err: "Couldn't get type for filter: nop1",
},
io{
Input: map[string]interface{}{
"filters": []interface{}{"nop1", "nop"},
"nop1": map[string]interface{}{
"type": 1,
},
},
Err: "Couldn't get type for filter: nop1",
},
}
for _, test := range tests {
_, err := LoadConfiguredFilters(test.Input)
assert.NotNil(t, err)
assert.Equal(t, test.Err, err.Error())
}
}