-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmocklogger_test.go
116 lines (100 loc) · 2.54 KB
/
mocklogger_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
package logger
import (
"testing"
router "github.com/Clever/kayvee-go/v7/router"
"github.com/stretchr/testify/assert"
)
func TestMockLoggerImplementsKayveeLogger(t *testing.T) {
assert.Implements(t, (*KayveeLogger)(nil), &MockRouteCountLogger{}, "*MockRouteCountLogger should implement KayveeLogger")
}
func TestRouteCountsWithMockLogger(t *testing.T) {
routes := map[string](router.Rule){
"rule-one": router.Rule{
Matchers: router.RuleMatchers{
"foo": []string{"bar", "baz"},
},
Output: router.RuleOutput{
"out": "#-%{foo}-",
},
},
"rule-two": router.Rule{
Matchers: router.RuleMatchers{
"abc": []string{"def"},
},
Output: router.RuleOutput{
"more": "x",
},
},
}
testRouter, err := router.NewFromRoutes(routes)
assert.NoError(t, err)
mockLogger := NewMockCountLogger("testing")
mockLogger.SetRouter(testRouter)
t.Log("log0")
data0 := M{
"wrong": "stuff",
}
mockLogger.InfoD("log0", data0)
t.Log("log0 -- verify rule counts")
actualCounts0 := mockLogger.RuleCounts()
expectedCounts0 := map[string]int{}
assert.Equal(t, expectedCounts0, actualCounts0)
t.Log("log0 -- verify rule matches")
actualRoutes0 := mockLogger.RuleOutputs()
expectedRoutes0 := map[string][]router.RuleOutput{}
assert.Equal(t, expectedRoutes0, actualRoutes0)
t.Log("log1")
data1 := M{
"foo": "bar",
}
mockLogger.InfoD("log1", data1)
t.Log("log1 -- verify rule counts")
actualCounts1 := mockLogger.RuleCounts()
expectedCounts1 := map[string]int{"rule-one": 1}
assert.Equal(t, expectedCounts1, actualCounts1)
t.Log("log1 -- verify rule matches")
actualRoutes1 := mockLogger.RuleOutputs()
expectedRoutes1 := map[string][]router.RuleOutput{
"rule-one": {
router.RuleOutput{
"rule": "rule-one",
"out": "#-bar-",
},
},
}
assert.Equal(t, expectedRoutes1, actualRoutes1)
t.Log("log2")
data2 := M{
"foo": "baz",
"abc": "def",
}
mockLogger.InfoD("log2", data2)
t.Log("log2 -- verify rule counts")
actualCounts2 := mockLogger.RuleCounts()
expectedCounts2 := map[string]int{
"rule-one": 2,
"rule-two": 1,
}
assert.Equal(t, expectedCounts2, actualCounts2)
t.Log("log2 -- verify rule matches")
expectedRoutes2 := map[string][]router.RuleOutput{
"rule-one": {
router.RuleOutput{
"rule": "rule-one",
"out": "#-bar-",
},
router.RuleOutput{
"rule": "rule-one",
"out": "#-baz-",
},
},
"rule-two": {
router.RuleOutput{
"rule": "rule-two",
"more": "x",
},
},
}
actualRoutes2 := mockLogger.RuleOutputs()
assert.Equal(t, expectedRoutes2, actualRoutes2)
}