]> git.r.bdr.sh - rbdr/mobius/blob - hotline/server_blackbox_test.go
Refactor and cleanup to improve testability
[rbdr/mobius] / hotline / server_blackbox_test.go
1 package hotline
2
3 import (
4 "github.com/stretchr/testify/assert"
5 "go.uber.org/zap"
6 "go.uber.org/zap/zapcore"
7 "os"
8 "testing"
9 )
10
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
28 // tranAssertEqual compares equality of transactions slices after stripping out the random ID
29 func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
30 var newT1 []Transaction
31 var newT2 []Transaction
32 for _, trans := range tran1 {
33 trans.ID = []byte{0, 0, 0, 0}
34 newT1 = append(newT1, trans)
35 }
36
37 for _, trans := range tran2 {
38 trans.ID = []byte{0, 0, 0, 0}
39 newT2 = append(newT2, trans)
40
41 }
42
43 return assert.Equal(t, newT1, newT2)
44 }