-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix logrus verbosity level checker (#369)
* fix verbosity checker * add test for verbosity checker
- Loading branch information
1 parent
61b061e
commit 83ed827
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
}) | ||
} | ||
} |