forked from timonwong/loggercheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstaticrules_test.go
52 lines (49 loc) · 1016 Bytes
/
staticrules_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
package loggercheck
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_mustNewStaticRuleSet_failCase(t *testing.T) {
testCases := []struct {
name string
rules []string
wantError string
}{
{
name: "nil",
wantError: "no rules provided",
},
{
name: "empty",
rules: []string{},
wantError: "no rules provided",
},
{
name: "multiple-rulesets",
rules: []string{
"(github.com/go-logr/logr.Logger).Error",
"k8s.io/klog/v2.InfoSDepth",
"(*go.uber.org/zap.SugaredLogger).Warnw",
},
wantError: "expected 1 ruleset, got 3",
},
{
name: "bad-rules",
rules: []string{
"# Comment",
" ",
"(*a/customonly.Logger).Debugw",
"xxx",
},
wantError: "error parse rule at line 2: invalid rule format",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
assert.PanicsWithError(t, tc.wantError, func() {
mustNewStaticRuleSet("custom", tc.rules)
})
})
}
}