]>
Commit | Line | Data |
---|---|---|
6988a057 JH |
1 | package hotline |
2 | ||
625b0580 | 3 | import ( |
00d1ef67 | 4 | "github.com/stretchr/testify/assert" |
625b0580 JH |
5 | "go.uber.org/zap" |
6 | "go.uber.org/zap/zapcore" | |
625b0580 | 7 | "os" |
625b0580 JH |
8 | "testing" |
9 | ) | |
10 | ||
625b0580 JH |
11 | func NewTestLogger() *zap.SugaredLogger { |
12 | encoderCfg := zap.NewProductionEncoderConfig() | |
13 | encoderCfg.TimeKey = "timestamp" | |
14 | encoderCfg.EncodeTime = zapcore.ISO8601TimeEncoder | |
15 | ||
16 | core := zapcore.NewCore( | |
17 | zapcore.NewConsoleEncoder(encoderCfg), | |
18 | zapcore.Lock(os.Stdout), | |
19 | zap.DebugLevel, | |
20 | ) | |
21 | ||
22 | cores := []zapcore.Core{core} | |
23 | l := zap.New(zapcore.NewTee(cores...)) | |
24 | defer func() { _ = l.Sync() }() | |
25 | return l.Sugar() | |
26 | } | |
27 | ||
aebc4d36 | 28 | // tranAssertEqual compares equality of transactions slices after stripping out the random ID |
00d1ef67 JH |
29 | func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool { |
30 | var newT1 []Transaction | |
31 | var newT2 []Transaction | |
92a7e455 JH |
32 | for _, trans := range tran1 { |
33 | trans.ID = []byte{0, 0, 0, 0} | |
00d1ef67 JH |
34 | newT1 = append(newT1, trans) |
35 | } | |
625b0580 | 36 | |
92a7e455 JH |
37 | for _, trans := range tran2 { |
38 | trans.ID = []byte{0, 0, 0, 0} | |
00d1ef67 | 39 | newT2 = append(newT2, trans) |
625b0580 | 40 | |
00d1ef67 | 41 | } |
625b0580 | 42 | |
00d1ef67 | 43 | return assert.Equal(t, newT1, newT2) |
92a7e455 | 44 | } |