-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_test.go
60 lines (46 loc) · 1.11 KB
/
logger_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
package natsby
import (
"bytes"
"errors"
"os"
"testing"
"github.com/nats-io/nats.go"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
)
func TestDefaultLogger(t *testing.T) {
logger := DefaultLogger()
assert.IsType(t, zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}), *logger)
}
func TestWithLogger(t *testing.T) {
var b bytes.Buffer
logger := zerolog.New(&b)
handler := WithLogger(&logger)
c := &Context{
Msg: &nats.Msg{
Subject: "test.subject",
Reply: "test.reply.inbox",
},
}
handler(c)
assert.Contains(t, b.String(), "test.subject")
assert.Contains(t, b.String(), "test.reply.inbox")
assert.Contains(t, b.String(), "latency")
}
func TestWithLoggerErr(t *testing.T) {
var b bytes.Buffer
logger := zerolog.New(&b)
handler := WithLogger(&logger)
c := &Context{
Msg: &nats.Msg{
Subject: "test.subject",
Reply: "test.reply.inbox",
},
Err: errors.New("Oops"),
}
handler(c)
assert.Contains(t, b.String(), "test.subject")
assert.Contains(t, b.String(), "test.reply.inbox")
assert.Contains(t, b.String(), "latency")
assert.Contains(t, b.String(), "Oops")
}