-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglog_test.go
55 lines (47 loc) · 1.08 KB
/
glog_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
package glog
import (
"bytes"
"testing"
"github.com/go-kit/kit/log"
"github.com/stretchr/testify/assert"
)
func TestSetLogger(t *testing.T) {
l := log.NewNopLogger()
SetLogger(l)
assert.Equal(t, l, logger)
}
func TestV(t *testing.T) {
assert.True(t, bool(V(0)))
}
func TestInfo(t *testing.T) {
var buf bytes.Buffer
SetLogger(log.NewJSONLogger(&buf))
testcases := []struct {
Name string
Args []interface{}
Expected string
}{{
Name: "String",
Args: []interface{}{"foo"},
Expected: `{"msg":"foo", "func":"Info", "level":"debug"}`,
}, {
Name: "Int",
Args: []interface{}{42},
Expected: `{"msg":"42", "func":"Info", "level":"debug"}`,
}, {
Name: "Bool",
Args: []interface{}{true},
Expected: `{"msg":"true", "func":"Info", "level":"debug"}`,
}, {
Name: "StringInt",
Args: []interface{}{"foo", 42},
Expected: `{"msg":"foo42", "func":"Info", "level":"debug"}`,
}}
for _, tc := range testcases {
t.Run(tc.Name, func(t *testing.T) {
Info(tc.Args...)
assert.JSONEq(t, tc.Expected, buf.String())
buf.Reset()
})
}
}