-
Notifications
You must be signed in to change notification settings - Fork 0
/
term_test.go
89 lines (85 loc) · 2.05 KB
/
term_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
package golog
import (
"bytes"
"testing"
)
func TestTermLogger(t *testing.T) {
t.Parallel()
level := LevelInfo
tests := []struct {
name string
kvs []interface{}
want string
}{
{
name: "Empty key value",
kvs: nil,
want: "",
},
{
name: "One key value",
kvs: []interface{}{"key1", "value1"},
want: "[INFO] key1:value1\n",
},
{
name: "Two key values",
kvs: []interface{}{"k1", 1, "k2", 2},
want: "[INFO] k1:1 k2:2\n",
},
{
name: "One key without value",
kvs: []interface{}{"k1"},
want: "[INFO] k1:KEY VALUES UNPAIRED\n",
},
{
name: "Timestamp key",
kvs: []interface{}{DefaultTimestampKeyName, 0},
want: "[0][INFO]\n",
},
{
name: "Timestamp key with key value",
kvs: []interface{}{DefaultTimestampKeyName, 0, "k1", "v1"},
want: "[0][INFO] k1:v1\n",
},
{
name: "Caller key",
kvs: []interface{}{DefaultCallerKeyName, "caller"},
want: "[caller][INFO]\n",
},
{
name: "Caller key with key value",
kvs: []interface{}{DefaultCallerKeyName, "caller", "k1", "v1"},
want: "[caller][INFO] k1:v1\n",
},
{
name: "Message key",
kvs: []interface{}{DefaultMsgKey, "msg value"},
want: "[INFO] msg value\n",
},
{
name: "Message key with key value",
kvs: []interface{}{DefaultMsgKey, "msg value", "k1", "v1"},
want: "[INFO] msg value k1:v1\n",
},
{
name: "Timestamp, Caller, Message key",
kvs: []interface{}{DefaultTimestampKeyName, 0, DefaultCallerKeyName, "caller", DefaultMsgKey, "msg value"},
want: "[0][caller][INFO] msg value\n",
},
{
name: "Timestamp, Caller, Message key with key value",
kvs: []interface{}{DefaultTimestampKeyName, 0, DefaultCallerKeyName, "caller", DefaultMsgKey, "msg value", "k1", "v1"},
want: "[0][caller][INFO] msg value k1:v1\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var buf bytes.Buffer
log := NewTermLogger(&buf, false)
log.Log(level, tt.kvs...)
if got := buf.String(); got != tt.want {
t.Errorf("buf.String() = %q want %q", got, tt.want)
}
})
}
}