-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathlogger_loop_test.go
More file actions
105 lines (99 loc) · 3.15 KB
/
Copy pathlogger_loop_test.go
File metadata and controls
105 lines (99 loc) · 3.15 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package loop_test
import (
"fmt"
"testing"
"time"
"github.com/hashicorp/go-plugin"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/test"
)
func TestHCLogLoggerPanic(t *testing.T) {
type testCase struct {
level int
expectedMessage string
expectedCustomKey string
expectedCustomValue string
expectedLogLevel zapcore.Level
}
tests := []testCase{
{
level: test.PANIC,
expectedMessage: "[PANIC] panic: random panic",
expectedCustomKey: "",
expectedCustomValue: "",
expectedLogLevel: zapcore.DPanicLevel,
},
{
level: test.FATAL,
expectedMessage: "[FATAL] some panic log",
expectedCustomKey: "custom-name-panic",
expectedCustomValue: "custom-value-panic",
expectedLogLevel: zapcore.DPanicLevel,
},
{
level: test.CRITICAL,
expectedMessage: "some critical error log",
expectedCustomKey: "custom-name-critical",
expectedCustomValue: "custom-value-critical",
expectedLogLevel: zapcore.DPanicLevel,
}, {
level: test.ERROR,
expectedMessage: "some error log",
expectedCustomKey: "custom-name-error",
expectedCustomValue: "custom-value-error",
expectedLogLevel: zapcore.ErrorLevel,
},
{
level: test.INFO,
expectedMessage: "some info log",
expectedCustomKey: "custom-name-info",
expectedCustomValue: "custom-value-info",
expectedLogLevel: zapcore.InfoLevel,
},
{
level: test.WARN,
expectedMessage: "some warn log",
expectedCustomKey: "custom-name-warn",
expectedCustomValue: "custom-value-warn",
expectedLogLevel: zapcore.WarnLevel,
},
{
level: test.DEBUG,
expectedMessage: "some debug log",
expectedCustomKey: "custom-name-debug",
expectedCustomValue: "custom-value-debug",
expectedLogLevel: zapcore.DebugLevel,
},
}
for _, tt := range tests {
t.Run(test.FormatLevel(tt.level), func(t *testing.T) {
t.Parallel()
lggr, ol := logger.TestObservedSugared(t, zapcore.DebugLevel)
loggerTest := &test.GRPCPluginLoggerTest{SugaredLogger: lggr}
cc := loggerTest.ClientConfig()
cc.Cmd = NewHelperProcessCommand(test.PluginLoggerTestName, false, tt.level)
c := plugin.NewClient(cc)
_, err := c.Client()
require.NoError(t, err)
time.Sleep(time.Second * 2) //wait for log to sync
c.Kill()
fLogs := ol.FilterMessage(tt.expectedMessage)
logs := fLogs.TakeAll()
require.Equal(t, len(logs), 1, fmt.Sprintf("could not find expected log %q", tt.expectedMessage))
require.Equal(t, tt.expectedMessage, logs[0].Message)
require.Equal(t, tt.expectedLogLevel, logs[0].Level)
if tt.expectedCustomKey != "" {
found := false
for _, e := range logs[0].Context {
if e.Key == tt.expectedCustomKey && e.String == tt.expectedCustomValue {
found = true
break
}
}
require.True(t, found, fmt.Sprintf("could not find expected values %s=%s", tt.expectedCustomKey, tt.expectedCustomValue))
}
})
}
}