-
Notifications
You must be signed in to change notification settings - Fork 5
/
logger_test.go
58 lines (51 loc) · 1.03 KB
/
logger_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
package log
import "testing"
func TestLogger_New(t *testing.T) {
lg1 := _New([]Option{
WithFormatter(JsonFormatter),
WithOutput(ConcurrentStderr),
WithLevel(InfoLevel),
})
lg2 := _New(nil)
lg2.SetFormatter(JsonFormatter)
lg2.SetOutput(ConcurrentStderr)
lg2.SetLevel(InfoLevel)
opts1 := lg1.getOptions()
opts2 := lg2.getOptions()
if *opts1 != *opts2 {
t.Errorf("have:%v, want:%v", opts1, opts2)
return
}
}
func TestLogger_SetOptions_GetOptions(t *testing.T) {
lg := _New(nil)
// default
{
opts := lg.getOptions()
want := options{
traceId: "",
formatter: TextFormatter,
output: ConcurrentStdout,
level: DebugLevel,
}
if have := *opts; have != want {
t.Errorf("have:%v, want:%v", have, want)
return
}
}
// set and get
{
opts := &options{
traceId: "123456789",
formatter: JsonFormatter,
output: ConcurrentStderr,
level: InfoLevel,
}
lg.setOptions(opts)
have := lg.getOptions()
if *have != *opts {
t.Errorf("have:%v, want:%v", have, opts)
return
}
}
}