-
Notifications
You must be signed in to change notification settings - Fork 7
/
level_test.go
60 lines (55 loc) · 1.39 KB
/
level_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
package log
import (
"strings"
"testing"
)
func TestLevelToString(t *testing.T) {
tests := []struct {
level Level
wantOut string
}{
{level: DEBUG, wantOut: "DEBUG"},
{level: INFO, wantOut: "INFO"},
{level: WARN, wantOut: "WARN"},
{level: ERROR, wantOut: "ERROR"},
{level: PANIC, wantOut: "PANIC"},
{level: FATAL, wantOut: "FATAL"},
{level: OFF, wantOut: "OFF"},
}
for _, tt := range tests {
got := tt.level.String()
if got != tt.wantOut {
t.Errorf("%v.String() output = %v, want %v", tt.level, got, tt.wantOut)
}
gotColor := tt.level.ColorString()
if !strings.Contains(gotColor, tt.wantOut) {
t.Errorf("%v.ColorString() output = %v, want %v", tt.level, gotColor, tt.wantOut)
}
}
}
func TestParseLevel(t *testing.T) {
tests := []struct {
name string
wantOut Level
wantErr bool
}{
{name: "debug", wantOut: DEBUG},
{name: "Info", wantOut: INFO},
{name: "WARN", wantOut: WARN},
{name: "error", wantOut: ERROR},
{name: "panic", wantOut: PANIC},
{name: "FATAL", wantOut: FATAL},
{name: "Off", wantOut: OFF},
{name: "xxxx", wantOut: 0, wantErr: true},
}
for _, tt := range tests {
got, err := ParseLevel(tt.name)
if (err != nil) != tt.wantErr {
t.Errorf("ParseLevel(%q) error = %v, wantErr %v", tt.name, err, tt.wantErr)
return
}
if got != tt.wantOut {
t.Errorf("ParseLevel(%q) output = %v, want %v", tt.name, got, tt.wantOut)
}
}
}