forked from vjeantet/grok
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tree_test.go
66 lines (61 loc) · 1.35 KB
/
tree_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
package grok
import (
"testing"
)
func TestTree(t *testing.T) {
cases := []map[string]string{
{
"aaa": "aa",
"bb": "%{aaa}, %{dd}",
"cc": "%{bb} %{aaa} %{dd}",
"dd": "%{cc} %{bb}",
},
{
"aaa": "aa",
"bb": "%{aaa}, %{dd}",
"cc": "%{bb} %{aaa} %{dd}",
"dd": "%{cc} %{bb}",
"ee": "%{ff}",
},
}
ret := [][2]map[string]string{
{
map[string]string{"aaa": "aa"},
map[string]string{
"bb": "circular dependency: pattern bb -> dd -> cc -> bb",
"cc": "circular dependency: pattern cc -> bb -> dd -> cc",
"dd": "circular dependency: pattern dd -> cc -> bb -> dd",
},
},
{
map[string]string{"aaa": "aa"},
map[string]string{
"bb": "circular dependency: pattern bb -> dd -> cc -> bb",
"cc": "circular dependency: pattern cc -> bb -> dd -> cc",
"dd": "circular dependency: pattern dd -> cc -> bb -> dd",
"ee": "no pattern found for %{ff}",
},
},
}
for i, pat := range cases {
v, errs := DenormalizePatternsFromMap(pat)
for k, v := range v {
expected, ok := ret[i][0][k]
if !ok {
t.Fatal("")
}
if expected != v.denormalized {
t.Errorf("value %s act: %s exp: %s", k, v, expected)
}
}
for k, v := range errs {
expected, ok := ret[i][1][k]
if !ok {
t.Fatal("")
}
if expected != v {
t.Errorf("error %s act: %s exp: %s", k, v, expected)
}
}
}
}