Skip to content

Commit 801cd1b

Browse files
committed
more tests
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
1 parent 41f0f04 commit 801cd1b

2 files changed

Lines changed: 90 additions & 2 deletions

File tree

internal/filter/filterconfig/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ var (
130130
ErrInvalidLogField = errors.New("services, span_names, span_kinds and metric_names are not valid for log records")
131131
ErrMissingRequiredLogField = errors.New(`at least one of "attributes", "libraries", "span_kinds", "resources", "log_bodies", "log_severity_texts" or "log_severity_number" field must be specified`)
132132
ErrMissingRequiredMetricField = errors.New(`at least one of "metric_names" or "resources" field must be specified`)
133-
ErrInvalidMetricField = errors.New("span_names, span_kinds, resources, log_bodies, log_severity_texts, log_severity_number, services, attributes and libraries are not valid for metrics")
133+
ErrInvalidMetricField = errors.New(`"span_names", "span_kinds", "log_bodies", "log_severity_texts", "log_severity_number", "services", "attributes" and "libraries" are not valid for metrics`)
134134

135135
spanKinds = map[string]bool{
136136
traceutil.SpanKindStr(ptrace.SpanKindInternal): true,

internal/filter/filterconfig/config_test.go

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func Test_CreateMetricMatchPropertiesFromDefault(t *testing.T) {
161161
want: nil,
162162
},
163163
{
164-
name: "invalid",
164+
name: "invalid log bodies",
165165
config: &MatchProperties{
166166
MetricNames: []string{"kind"},
167167
Config: filterset.Config{
@@ -172,6 +172,94 @@ func Test_CreateMetricMatchPropertiesFromDefault(t *testing.T) {
172172
want: nil,
173173
wantErr: true,
174174
},
175+
{
176+
name: "invalid log severity texts",
177+
config: &MatchProperties{
178+
MetricNames: []string{"kind"},
179+
Config: filterset.Config{
180+
MatchType: filterset.Regexp,
181+
},
182+
LogSeverityTexts: []string{"text"},
183+
},
184+
want: nil,
185+
wantErr: true,
186+
},
187+
{
188+
name: "invalid log severity number",
189+
config: &MatchProperties{
190+
MetricNames: []string{"kind"},
191+
Config: filterset.Config{
192+
MatchType: filterset.Regexp,
193+
},
194+
LogSeverityNumber: &LogSeverityNumberMatchProperties{},
195+
},
196+
want: nil,
197+
wantErr: true,
198+
},
199+
{
200+
name: "invalid span names",
201+
config: &MatchProperties{
202+
MetricNames: []string{"kind"},
203+
Config: filterset.Config{
204+
MatchType: filterset.Regexp,
205+
},
206+
SpanNames: []string{"text"},
207+
},
208+
want: nil,
209+
wantErr: true,
210+
},
211+
{
212+
name: "invalid span kinds",
213+
config: &MatchProperties{
214+
MetricNames: []string{"kind"},
215+
Config: filterset.Config{
216+
MatchType: filterset.Regexp,
217+
},
218+
SpanKinds: []string{"text"},
219+
},
220+
want: nil,
221+
wantErr: true,
222+
},
223+
{
224+
name: "invalid services",
225+
config: &MatchProperties{
226+
MetricNames: []string{"kind"},
227+
Config: filterset.Config{
228+
MatchType: filterset.Regexp,
229+
},
230+
Services: []string{"text"},
231+
},
232+
want: nil,
233+
wantErr: true,
234+
},
235+
{
236+
name: "invalid attributes",
237+
config: &MatchProperties{
238+
MetricNames: []string{"kind"},
239+
Config: filterset.Config{
240+
MatchType: filterset.Regexp,
241+
},
242+
Attributes: []Attribute{
243+
{Key: "key", Value: "val"},
244+
},
245+
},
246+
want: nil,
247+
wantErr: true,
248+
},
249+
{
250+
name: "invalid span kinds",
251+
config: &MatchProperties{
252+
MetricNames: []string{"kind"},
253+
Config: filterset.Config{
254+
MatchType: filterset.Regexp,
255+
},
256+
Libraries: []InstrumentationLibrary{
257+
{Name: "name"},
258+
},
259+
},
260+
want: nil,
261+
wantErr: true,
262+
},
175263
{
176264
name: "valid",
177265
config: &MatchProperties{

0 commit comments

Comments
 (0)