-
Notifications
You must be signed in to change notification settings - Fork 1
/
testing_test.go
59 lines (43 loc) · 1.23 KB
/
testing_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
package logger_test
import (
"testing"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
logger "github.com/blendle/go-logger"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTestNew(t *testing.T) {
t.Parallel()
logger, logs := logger.TestNew(t)
logger.Debug("")
assert.Len(t, logs.All(), 1)
}
func TestTestNewWarn(t *testing.T) {
t.Parallel()
logger, logs := logger.TestNewWarn(t)
logger.Debug("")
logger.Warn("")
logger.Error("")
require.Len(t, logs.All(), 2)
assert.Equal(t, zapcore.WarnLevel, logs.All()[0].Level)
assert.Equal(t, zapcore.ErrorLevel, logs.All()[1].Level)
}
func TestTestNewWithLevel(t *testing.T) {
t.Parallel()
logger, logs := logger.TestNewWithLevel(t, zapcore.ErrorLevel)
logger.Debug("")
logger.Warn("")
logger.Error("")
logger.DPanic("")
require.Len(t, logs.All(), 2)
assert.Equal(t, zapcore.ErrorLevel, logs.All()[0].Level)
assert.Equal(t, zapcore.DPanicLevel, logs.All()[1].Level)
}
func TestTestNewWithLevel_WithOptions(t *testing.T) {
t.Parallel()
logger, logs := logger.TestNewWithLevel(t, zapcore.WarnLevel, zap.Fields(zap.Int("1", 1)))
logger.Error("error")
require.Len(t, logs.All(), 1)
assert.Equal(t, int64(1), logs.All()[0].ContextMap()["1"])
}