-
Notifications
You must be signed in to change notification settings - Fork 1
/
std_test.go
104 lines (92 loc) · 2.47 KB
/
std_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
package logger
import (
"bytes"
"context"
"log"
"os"
"testing"
)
func Test_stdErrLogger(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
t.Cleanup(func() { log.SetOutput(os.Stderr) })
type args struct {
v []interface{}
v2 interface{}
}
tests := []struct {
name string
args args
wantDebug string
wantDebugf string
wantInfo string
wantInfof string
wantWarn string
wantWarnf string
wantError string
wantErrorf string
}{
{
name: "Test 1",
args: args{
v: []interface{}{"Message"},
v2: "Message",
},
wantDebug: "DEBUG: Message\n",
wantDebugf: "DEBUG: Formatted Message\n",
wantInfo: "INFO : Message\n",
wantInfof: "INFO : Formatted Message\n",
wantWarn: "WARN : Message\n",
wantWarnf: "WARN : Formatted Message\n",
wantError: "ERROR: Message\n",
wantErrorf: "ERROR: Formatted Message\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.Background()
l := &stdErrLogger{}
format := "Formatted %s"
l.Debug(ctx, tt.args.v2)
if s := buf.String()[20:]; s != tt.wantDebug {
t.Errorf("stdErrLogger.Debug() value = %v, wantValue %v", s, tt.wantDebug)
}
buf.Reset()
l.Debugf(ctx, format, tt.args.v...)
if s := buf.String()[20:]; s != tt.wantDebugf {
t.Errorf("stdErrLogger.Debug() value = %v, wantValue %v", s, tt.wantDebugf)
}
buf.Reset()
l.Info(ctx, tt.args.v2)
if s := buf.String()[20:]; s != tt.wantInfo {
t.Errorf("stdErrLogger.Info() value = %v, wantValue %v", s, tt.wantInfo)
}
buf.Reset()
l.Infof(ctx, format, tt.args.v...)
if s := buf.String()[20:]; s != tt.wantInfof {
t.Errorf("stdErrLogger.Info() value = %v, wantValue %v", s, tt.wantInfof)
}
buf.Reset()
l.Warn(ctx, tt.args.v2)
if s := buf.String()[20:]; s != tt.wantWarn {
t.Errorf("stdErrLogger.Warn() value = %v, wantValue %v", s, tt.wantWarn)
}
buf.Reset()
l.Warnf(ctx, format, tt.args.v...)
if s := buf.String()[20:]; s != tt.wantWarnf {
t.Errorf("stdErrLogger.Warn() value = %v, wantValue %v", s, tt.wantWarnf)
}
buf.Reset()
l.Error(ctx, tt.args.v2)
if s := buf.String()[20:]; s != tt.wantError {
t.Errorf("stdErrLogger.Error() value = %v, wantValue %v", s, tt.wantError)
}
buf.Reset()
l.Errorf(ctx, format, tt.args.v...)
if s := buf.String()[20:]; s != tt.wantErrorf {
t.Errorf("stdErrLogger.Error() value = %v, wantValue %v", s, tt.wantErrorf)
}
buf.Reset()
})
}
}