-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger_test.go
52 lines (39 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
package proxyprotocol_test
import (
"reflect"
"testing"
"github.com/c0va23/go-proxyprotocol"
"github.com/golang/mock/gomock"
)
func TestLoggerFunc(t *testing.T) {
var format string
var args []interface{}
innerLogger := func(f string, v ...interface{}) {
format = f
args = v
}
logger := proxyprotocol.LoggerFunc(innerLogger)
expectedFormat := "format %s %d"
expectedArgs := []interface{}{"test", 123}
logger.Printf(expectedFormat, expectedArgs...)
if format != expectedFormat {
t.Errorf("Uexpected format %s", format)
}
if !reflect.DeepEqual(args, expectedArgs) {
t.Errorf("Unexpected args %v", args)
}
}
func TestFallbackLogger_Printf(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
t.Run("when inner logger is nil", func(t *testing.T) {
logger := proxyprotocol.FallbackLogger{Logger: nil}
logger.Printf("Test")
})
t.Run("when inner logger valid logger", func(t *testing.T) {
innerLogger := NewMockLogger(mockCtrl)
innerLogger.EXPECT().Printf("Debug %s", 123)
logger := proxyprotocol.FallbackLogger{Logger: innerLogger}
logger.Printf("Debug %s", 123)
})
}