-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmessage_test.go
115 lines (111 loc) · 2.51 KB
/
message_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
package clog
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_newMessage(t *testing.T) {
t.Run("no skip", func(t *testing.T) {
tests := []struct {
name string
level Level
format string
v []interface{}
want string
}{
{
name: "trace",
level: LevelTrace,
format: "a trace log: %v",
v: []interface{}{"value"},
want: "[TRACE] a trace log: value",
},
{
name: "info",
level: LevelInfo,
format: "a info log: %v",
v: []interface{}{"value"},
want: "[ INFO] a info log: value",
},
{
name: "warn",
level: LevelWarn,
format: "a warn log: %v",
v: []interface{}{"value"},
want: "[ WARN] a warn log: value",
},
{
name: "error",
level: LevelError,
format: "an error log: %v",
v: []interface{}{"value"},
want: "[ERROR] an error log: value",
},
{
name: "fatal",
level: LevelFatal,
format: "a fatal log: %v",
v: []interface{}{"value"},
want: "[FATAL] a fatal log: value",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := newMessage(tt.level, 0, tt.format, tt.v...)
assert.Equal(t, tt.level, m.Level())
assert.Equal(t, tt.want, m.String())
})
}
})
t.Run("has skip", func(t *testing.T) {
tests := []struct {
name string
level Level
format string
v []interface{}
contains string
}{
{
name: "trace",
level: LevelTrace,
format: "a trace log: %v",
v: []interface{}{"value"},
contains: "[TRACE] a trace log: value",
},
{
name: "info",
level: LevelInfo,
format: "a info log: %v",
v: []interface{}{"value"},
contains: "[ INFO] a info log: value",
},
{
name: "warn",
level: LevelWarn,
format: "a warn log: %v",
v: []interface{}{"value"},
contains: "[ WARN] a warn log: value",
},
{
name: "error",
level: LevelError,
format: "an error log: %v",
v: []interface{}{"value"},
contains: "an error log: value",
},
{
name: "fatal",
level: LevelFatal,
format: "a fatal log: %v",
v: []interface{}{"value"},
contains: "()] a fatal log: value",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := newMessage(tt.level, 1, tt.format, tt.v...)
assert.Equal(t, tt.level, m.Level())
assert.Contains(t, m.String(), tt.contains)
})
}
})
}