-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstd_test.go
50 lines (46 loc) · 936 Bytes
/
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
package golog
import (
"bytes"
"testing"
)
// Test that stdLogger properly record logs.
func TestStdLogger(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",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var buf bytes.Buffer
log := NewStdLogger(&buf)
log.Log(level, tt.kvs...)
if got := buf.String(); got != tt.want {
t.Errorf("buf.String() = %q want %q", got, tt.want)
}
})
}
}