-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlevels_test.go
172 lines (157 loc) · 3.82 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package discordrus
import (
"reflect"
"testing"
"github.com/sirupsen/logrus"
)
// TestAllLevels ensures that logrus' AllLevels has not changed
func TestAllLevels(t *testing.T) {
// AllLevels is a slice of all the supported Logrus levels
var AllLevels = []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
logrus.WarnLevel,
logrus.InfoLevel,
logrus.DebugLevel,
logrus.TraceLevel,
}
if !reflect.DeepEqual(AllLevels, logrus.AllLevels) {
t.Error("discordrus' AllLevels is not the same as logrus' AllLevels")
}
}
// TestLevelThreshold ensures that the slice returned contains the correct level
func TestLevelThreshold(t *testing.T) {
var expectedTraceThreshold = []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
logrus.WarnLevel,
logrus.InfoLevel,
logrus.DebugLevel,
logrus.TraceLevel,
}
var expectedDebugThreshold = []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
logrus.WarnLevel,
logrus.InfoLevel,
logrus.DebugLevel,
}
var expectedPanicThreshold = []logrus.Level{
logrus.PanicLevel,
}
var expectedErrorThreshold = []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
}
// Test extreme boundaries
traceThreshold := LevelThreshold(logrus.TraceLevel)
if !reflect.DeepEqual(traceThreshold, expectedTraceThreshold) {
t.Error("Trace threshold does not match expected slice")
}
debugThreshold := LevelThreshold(logrus.DebugLevel)
if !reflect.DeepEqual(debugThreshold, expectedDebugThreshold) {
t.Error("Debug threshold does not match expected slice")
}
panicThreshold := LevelThreshold(logrus.PanicLevel)
if !reflect.DeepEqual(panicThreshold, expectedPanicThreshold) {
t.Error("Panic threshold does not match expected slice")
}
// Test within boundaries
errorThreshold := LevelThreshold(logrus.ErrorLevel)
if !reflect.DeepEqual(errorThreshold, expectedErrorThreshold) {
t.Error("Error threshold does not match expected slice")
}
}
// TestLevelColor ensures LevelColor is able to return the respect color for both default and custom LevelColors
func TestLevelColor(t *testing.T) {
// Set up custom LevelColors
customLevelColors := LevelColors{
Trace: 1,
Debug: 2,
Info: 3,
Warn: 4,
Error: 5,
Panic: 6,
Fatal: 7,
}
defaultColors := []struct {
expected int
input logrus.Level
}{
{
input: logrus.TraceLevel,
expected: DefaultLevelColors.Trace,
},
{
input: logrus.DebugLevel,
expected: DefaultLevelColors.Debug,
},
{
input: logrus.InfoLevel,
expected: DefaultLevelColors.Info,
},
{
input: logrus.WarnLevel,
expected: DefaultLevelColors.Warn,
},
{
input: logrus.ErrorLevel,
expected: DefaultLevelColors.Error,
},
{
input: logrus.PanicLevel,
expected: DefaultLevelColors.Panic,
},
{
input: logrus.FatalLevel,
expected: DefaultLevelColors.Fatal,
},
}
for _, c := range defaultColors {
if c.expected != DefaultLevelColors.LevelColor(c.input) {
t.Errorf("Error color for default: %s is not as expected", c.input)
}
}
customColors := []struct {
expected int
input logrus.Level
}{
{
expected: customLevelColors.Trace,
input: logrus.TraceLevel,
},
{
expected: customLevelColors.Debug,
input: logrus.DebugLevel,
},
{
expected: customLevelColors.Info,
input: logrus.InfoLevel,
},
{
expected: customLevelColors.Warn,
input: logrus.WarnLevel,
},
{
expected: customLevelColors.Error,
input: logrus.ErrorLevel,
},
{
expected: customLevelColors.Panic,
input: logrus.PanicLevel,
},
{
expected: customLevelColors.Fatal,
input: logrus.FatalLevel,
},
}
for _, c := range customColors {
if c.expected != customLevelColors.LevelColor(c.input) {
t.Errorf("Panic color for custom: %s is not as expected", c.input)
}
}
}