-
Notifications
You must be signed in to change notification settings - Fork 0
/
levels_test.go
97 lines (80 loc) · 2.04 KB
/
levels_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
package hook
import (
"fmt"
"testing"
"github.com/sirupsen/logrus"
)
func TestParseLevels(t *testing.T) {
// Test not empty lvs and not empty minLvl
testParseLevels(
t,
[]logrus.Level{logrus.ErrorLevel, logrus.WarnLevel, logrus.InfoLevel},
[]string{"error", "warning", "info", "trace"},
"info",
)
// Test empty lvs and empty minLvl
testParseLevels(t, logrus.AllLevels, []string{}, "")
// Test not empty lvs and empty minLvl
testParseLevels(
t,
[]logrus.Level{logrus.ErrorLevel, logrus.WarnLevel, logrus.InfoLevel, logrus.TraceLevel},
[]string{"error", "warning", "info", "trace"},
"",
)
// Test parse min level error
func() {
expErrStr := `discordbotrus: not a valid logrus Level: "fake"`
_, err := ParseLevels(nil, "fake")
if err == nil {
t.Errorf("expect error: %s got error: nil", expErrStr)
return
}
if err.Error() != expErrStr {
t.Errorf("expect error: %s got error: %s", expErrStr, err)
}
}()
// Test parse levels error
func() {
expErrStr := `discordbotrus: not a valid logrus Level: "wrong"`
_, err := ParseLevels([]string{"error", "warning", "wrong", "trace"}, "")
if err == nil {
t.Errorf("expect error: %s got error: nil", expErrStr)
return
}
if err.Error() != expErrStr {
t.Errorf("expect error: %s got error: %s", expErrStr, err)
}
}()
}
func TestLevelColor(t *testing.T) {
levels := logrus.AllLevels
for _, level := range levels {
color := LevelColor(level)
if color == 0 {
t.Errorf("enexpected color for level: %v", level)
break
}
}
color := LevelColor(logrus.Level(999))
if color != 0 {
t.Error("enexpected color for nonexistent level")
}
}
func testParseLevels(t *testing.T, exp []logrus.Level, lvs []string, minLvl string) {
levels, err := ParseLevels(lvs, minLvl)
if err != nil {
t.Errorf("exp error: nil got error: %s", err)
return
}
if len(levels) != len(exp) {
fmt.Println(levels)
t.Error("levels len not equal exp len")
return
}
for k, v := range exp {
if levels[k] != v {
t.Errorf("exp %v got %v", v, levels[k])
return
}
}
}