-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
89 lines (81 loc) · 1.81 KB
/
options_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
package zl
import (
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/zap/zapcore"
)
func TestSetOutput(t *testing.T) {
tests := []Output{PrettyOutput, ConsoleAndFileOutput, ConsoleOutput, FileOutput}
for _, tt := range tests {
t.Run(tt.String(), func(t *testing.T) {
SetOutput(tt)
assert.Equal(t, tt, outputType)
})
}
}
func TestSetOutputByString(t *testing.T) {
tests := []struct {
in string
out Output
}{
{"Pretty", PrettyOutput},
{"ConsoleAndFile", ConsoleAndFileOutput},
{"Console", ConsoleOutput},
{"File", FileOutput},
{"", PrettyOutput},
}
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
SetOutputByString(tt.in)
assert.Equal(t, tt.out, outputType)
})
}
}
func TestSetLevel(t *testing.T) {
tests := []zapcore.Level{DebugLevel, InfoLevel, WarnLevel, ErrorLevel, FatalLevel}
for _, tt := range tests {
t.Run(tt.String(), func(t *testing.T) {
SetLevel(tt)
assert.Equal(t, tt, severityLevel)
ResetGlobalLoggerSettings()
})
}
}
func TestSetLevelByString(t *testing.T) {
tests := []struct {
in string
out zapcore.Level
}{
{"debug", DebugLevel},
{"info", InfoLevel},
{"warn", WarnLevel},
{"error", ErrorLevel},
{"fatal", FatalLevel},
}
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
SetLevelByString(tt.in)
assert.Equal(t, tt.out, severityLevel)
ResetGlobalLoggerSettings()
})
}
}
func TestSetFieldKey(t *testing.T) {
SetFieldKey(FunctionKey, "func")
SetFieldKey(StacktraceKey, "stack_trace")
SetFieldKey(CallerKey, "")
SetFieldKey("", "abc")
assert.Equal(t,
map[Key]string{
FunctionKey: "func",
StacktraceKey: "stack_trace",
},
fieldKeys,
)
ResetGlobalLoggerSettings()
}
func TestSetSeparator(t *testing.T) {
SetSeparator(":")
assert.Equal(t, ":", separator)
ResetGlobalLoggerSettings()
}