-
Notifications
You must be signed in to change notification settings - Fork 0
/
glogger_test.go
198 lines (189 loc) · 3.37 KB
/
glogger_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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package glog
import (
"os"
"testing"
)
const testFile = "test.log"
func TestUnstructureGlogger(t *testing.T) {
type args struct {
filePath string
options []Options
}
tests := []struct {
name string
args args
wantNil bool
}{
{
name: "success",
args: args{
filePath:testFile,
options: []Options{},
},
wantNil: false,
},
{
name: "fail",
args: args{
filePath: "unknown/path/test.log",
options: []Options{},
},
wantNil: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewUnstructureGlogger(tt.args.filePath, tt.args.options...); !tt.wantNil && (got == nil) {
t.Errorf("UnstructureGlogger() = %v, want %v", got, "valid logger")
}
})
}
os.RemoveAll(testFile)
}
func TestJSONGlogger(t *testing.T) {
type args struct {
filePath string
options []Options
}
tests := []struct {
name string
args args
wantNil bool
}{
{
name: "success",
args: args{
filePath:testFile,
options: []Options{},
},
wantNil: false,
},
{
name: "fail",
args: args{
filePath: "unknown/path/test.log",
options: []Options{},
},
wantNil: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewJSONGlogger(tt.args.filePath, tt.args.options...); !tt.wantNil && (got == nil) {
t.Errorf("JSONGlogger() = %v, want %v", got, "valid logger")
}
})
}
}
func TestLogLevel_string(t *testing.T) {
tests := []struct {
name string
level LogLevel
want string
}{
{
name: "Info",
level: INFO,
want: "INFO",
},
{
name: "Debug",
level: DEBUG,
want: "DEBUG",
},
{
name: "Error",
level: ERROR,
want: "ERROR",
},
{
name: "Warn",
level: WARN,
want: "WARN",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.level.string(); got != tt.want {
t.Errorf("LogLevel.string() = %v, want %v", got, tt.want)
}
})
}
}
func TestDefaultGlog_log(t *testing.T) {
type args struct {
format string
level LogLevel
msg []interface{}
}
tests := []struct {
name string
g *UnstructureGlog
args args
}{
{
name: "success",
g: defaultGlogger,
args: args{
format: "%s",
level: ERROR,
msg: []interface{}{"Success"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Error(tt.args.msg...)
Info(tt.args.msg...)
Warn(tt.args.msg...)
Debug(tt.args.msg...)
})
}
os.RemoveAll(testFile)
}
func TestDefaultGlog_logf(t *testing.T) {
type args struct {
format string
level LogLevel
msg []interface{}
}
tests := []struct {
name string
g *UnstructureGlog
args args
}{
{
name: "success",
g: defaultGlogger,
args: args{
format: "%s",
level: ERROR,
msg: []interface{}{"Success"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Errorf(tt.args.format, tt.args.msg...)
Infof(tt.args.format, tt.args.msg...)
Warnf(tt.args.format, tt.args.msg...)
Debugf(tt.args.format, tt.args.msg...)
})
}
os.RemoveAll(testFile)
}
// func TestCleanup(t *testing.T) {
// tests := []struct {
// name string
// }{
// {
// name: "cleanup",
// },
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// defaultGlogger.Info("cleanup")
// Cleanup()
// })
// }
// }