generated from logur/integration-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_test.go
67 lines (53 loc) · 1.34 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
61
62
63
64
65
66
67
package zap
import (
"testing"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"logur.dev/logur"
"logur.dev/logur/logtesting"
)
func TestWith(t *testing.T) {
logger := &logur.TestLogger{}
log := New(logger)
log.With(zap.String("foo", "bar")).Info("hello", zap.String("baz", "quux"))
logEvent := logur.LogEvent{
Line: "hello",
Level: logur.Info,
Fields: map[string]interface{}{
"foo": "bar",
"baz": "quux",
},
}
logtesting.AssertLogEventsEqual(t, logEvent, *(logger.LastEvent()))
}
func TestLogger(t *testing.T) {
const msg = "hello"
logger := &logur.TestLogger{}
log := New(logger)
tests := []struct {
f func(string, ...zapcore.Field)
level zapcore.Level
want logur.Level
}{
{log.Debug, zapcore.DebugLevel, logur.Debug},
{log.Info, zapcore.InfoLevel, logur.Info},
{log.Warn, zapcore.WarnLevel, logur.Warn},
{log.Error, zapcore.ErrorLevel, logur.Error},
{log.DPanic, zapcore.DPanicLevel, logur.Error},
}
for _, test := range tests {
test := test
t.Run(test.want.String(), func(t *testing.T) {
test.f(msg)
logEvent := logur.LogEvent{
Line: msg,
Level: test.want,
}
logtesting.AssertLogEventsEqual(t, logEvent, *(logger.LastEvent()))
if ce := log.Check(test.level, msg); ce != nil {
ce.Write()
}
logtesting.AssertLogEventsEqual(t, logEvent, *(logger.LastEvent()))
})
}
}