-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel_test.go
More file actions
141 lines (124 loc) · 2.49 KB
/
level_test.go
File metadata and controls
141 lines (124 loc) · 2.49 KB
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
package logger
import (
"context"
"fmt"
"testing"
"go.uber.org/zap"
)
type slave struct{}
func (slave) Write(p []byte) (n int, err error) {
// do something with log data
fmt.Println("slave: ", string(p))
return
}
type slave2 struct{}
func (slave2) Write(p []byte) (n int, err error) {
// do something with log data
fmt.Println("slave2: ", string(p))
return
}
func TestLevel(t *testing.T) {
I("msg", "key", "val")
D("msg", "key", "val")
W("msg", "key", "val")
E("msg", "key", "val")
}
func TestLevelPanic(t *testing.T) {
defer func() {
e := recover()
if e == "this is a panic" {
t.Fatal()
}
}()
P("this is a panic", "key", "val")
}
func TestFatal(t *testing.T) {
defer func() {
t.Fatal("you can not see this line.")
}()
F("msg", "key", "val")
}
func TestRegisterDebug(t *testing.T) {
if _autoLevel.Level() == zap.DebugLevel {
t.Fail()
}
RegisterDebug(true)
if _autoLevel.Level() != zap.DebugLevel {
t.Fail()
}
RegisterDebug(false)
if _autoLevel.Level() == zap.DebugLevel {
t.Fail()
}
}
func TestRegisterWriter(t *testing.T) {
RegisterWriter(new(slave))
I("msg", "key", "val")
RegisterWriter(new(slave2))
I("msg", "key", "val")
}
func TestRegisterWriter2(t *testing.T) {
RegisterWriter(new(slave), new(slave2))
I("msg", "key", "val")
}
func TestRegisterErrorWriter(t *testing.T) {
RegisterErrorWriter(new(slave), new(slave2))
RegisterServiceName("svc name")
E("msg", "key", "val")
}
func TestRegisterServiceName(t *testing.T) {
RegisterServiceName("Monaco")
RegisterWriter(new(slave))
I("msg", "key", "val")
}
func TestLog(t *testing.T) {
var mockStruct = struct{ key string }{key: "value"}
type args struct {
args []interface{}
}
tests := []struct {
name string
args args
}{
{
name: "T",
args: args{
[]interface{}{"key1", mockStruct, "key2", mockStruct},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Log(tt.args.args...)
})
}
}
func Test_contextLogger_I(t *testing.T) {
type fields struct {
ctx context.Context
}
type args struct {
msg string
keyValues []interface{}
}
tests := []struct {
name string
fields fields
args args
}{
{
fields: fields{},
args: args{
msg: "test",
keyValues: []interface{}{"key1", "val1", "key2", "val2"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.TODO()
WithContext(&ctx).I(tt.args.msg, tt.args.keyValues...)
WithContext(&ctx).I(tt.args.msg, tt.args.keyValues...)
})
}
}