forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoop.rb
163 lines (137 loc) · 3.49 KB
/
noop.rb
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
require "test_utils"
require "logstash/filters/noop"
#NOOP filter is perfect for testing Filters::Base features with minimal overhead
describe LogStash::Filters::NOOP do
extend LogStash::RSpec
describe "adding multiple value to one field" do
config <<-CONFIG
filter {
noop {
add_field => ["new_field", "new_value"]
add_field => ["new_field", "new_value_2"]
}
}
CONFIG
sample "example" do
insist { subject["new_field"] } == ["new_value", "new_value_2"]
end
end
describe "type parsing" do
config <<-CONFIG
filter {
noop {
type => "noop"
add_tag => ["test"]
}
}
CONFIG
sample({"@type" => "noop"}) do
insist { subject.tags } == ["test"]
end
sample({"@type" => "not_noop"}) do
insist { subject.tags } == []
end
end
describe "tags parsing with one tag" do
config <<-CONFIG
filter {
noop {
type => "noop"
tags => ["t1"]
add_tag => ["test"]
}
}
CONFIG
sample({"@type" => "noop"}) do
insist { subject.tags} == []
end
sample({"@type" => "noop", "@tags" => ["t1", "t2"]}) do
insist { subject.tags} == ["t1", "t2", "test"]
end
end
describe "tags parsing with multiple tags" do
config <<-CONFIG
filter {
noop {
type => "noop"
tags => ["t1", "t2"]
add_tag => ["test"]
}
}
CONFIG
sample({"@type" => "noop"}) do
insist { subject.tags} == []
end
sample({"@type" => "noop", "@tags" => ["t1"]}) do
insist { subject.tags} == ["t1"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t2"]}) do
insist { subject.tags} == ["t1", "t2", "test"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t2", "t3"]}) do
insist { subject.tags} == ["t1", "t2", "t3", "test"]
end
end
describe "exclude_tags with 1 tag" do
config <<-CONFIG
filter {
noop {
type => "noop"
tags => ["t1"]
add_tag => ["test"]
exclude_tags => ["t2"]
}
}
CONFIG
sample({"@type" => "noop"}) do
insist { subject.tags} == []
end
sample({"@type" => "noop", "@tags" => ["t1"]}) do
insist { subject.tags} == ["t1", "test"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t2"]}) do
insist { subject.tags} == ["t1", "t2"]
end
end
describe "exclude_tags with >1 tags" do
config <<-CONFIG
filter {
noop {
type => "noop"
tags => ["t1"]
add_tag => ["test"]
exclude_tags => ["t2", "t3"]
}
}
CONFIG
sample({"@type" => "noop", "@tags" => ["t1", "t2", "t4"]}) do
insist { subject.tags} == ["t1", "t2", "t4"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t3", "t4"]}) do
insist { subject.tags} == ["t1", "t3", "t4"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t4", "t5"]}) do
insist { subject.tags} == ["t1", "t4", "t5", "test"]
end
end
describe "remove_tag" do
config <<-CONFIG
filter {
noop {
type => "noop"
tags => ["t1"]
remove_tag => ["t2", "t3"]
}
}
CONFIG
sample({"@type" => "noop", "@tags" => ["t4"]}) do
insist { subject.tags} == ["t4"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t2", "t3"]}) do
insist { subject.tags} == ["t1"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t2"]}) do
insist { subject.tags} == ["t1"]
end
end
end