forked from grpc-ecosystem/go-grpc-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpclogger_test.go
71 lines (66 loc) · 1.73 KB
/
grpclogger_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
60
61
62
63
64
65
66
67
68
69
70
71
package grpc_logrus
import (
"testing"
"github.com/sirupsen/logrus"
)
func Test_logrusGrpcLoggerV2_V(t *testing.T) {
tests := []struct {
name string
setupLevel logrus.Level
inLevel logrus.Level
want bool
}{
{
name: "WarnLevel setup when we have WarnLevel msg should return TRUE",
setupLevel: logrus.WarnLevel,
inLevel: logrus.WarnLevel,
want: true,
},
{
name: "WarnLevel setup when we have ErrorLevel msg should return TRUE",
setupLevel: logrus.WarnLevel,
inLevel: logrus.ErrorLevel,
want: true,
},
{
name: "WarnLevel setup when we have InfoLevel msg should return FALSE",
setupLevel: logrus.WarnLevel,
inLevel: logrus.InfoLevel,
want: false,
},
{
name: "WarnLevel setup when we have DebugLevel msg should return FALSE",
setupLevel: logrus.WarnLevel,
inLevel: logrus.DebugLevel,
want: false,
},
{
name: "WarnLevel setup when we have TraceLevel msg should return FALSE",
setupLevel: logrus.WarnLevel,
inLevel: logrus.TraceLevel,
want: false,
},
{
name: "TraceLevel setup when we have WarnLevel msg should return TRUE",
setupLevel: logrus.TraceLevel,
inLevel: logrus.WarnLevel,
want: true,
},
{
name: "TraceLevel setup when we have TraceLevel msg should return TRUE",
setupLevel: logrus.TraceLevel,
inLevel: logrus.TraceLevel,
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lr := logrus.New()
lr.SetLevel(tt.setupLevel)
l := &logrusGrpcLoggerV2{logrus.NewEntry(lr)}
if got := l.V(int(tt.inLevel)); got != tt.want {
t.Errorf("V() = %v, want %v", got, tt.want)
}
})
}
}