-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstd_extractor_test.go
54 lines (50 loc) · 1002 Bytes
/
std_extractor_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
package colog
import (
"testing"
)
type extractInOut struct {
in string
outMsg string
outData map[string]interface{}
}
var extractorTests = []extractInOut{
{
"some message foo=bar",
"some message",
map[string]interface{}{"foo": "bar"},
},
{
"some message foo=42 foo2='other bar'",
"some message",
map[string]interface{}{
"foo": "42",
"foo2": "other bar",
},
},
{
"some foo=42 otherfoo='other bar' mixed text",
"some mixed text",
map[string]interface{}{
"foo": "42",
"otherfoo": "other bar",
},
},
}
func TestStdExtractor(t *testing.T) {
stde := StdExtractor{}
for _, tt := range extractorTests {
e := &Entry{
Message: []byte(tt.in),
Fields: make(Fields),
}
stde.Extract(e)
if string(e.Message) != tt.outMsg {
t.Errorf("Extract error:\n %s\n %s", string(e.Message), tt.outMsg)
}
for k, v := range tt.outData {
if e.Fields[k] != v {
t.Errorf("Invalid data value %s\n %s vs %s", k, v, e.Fields[k])
}
}
}
}