test(middleware/logging): TestExtractError (#2443)

pull/2447/head
jesse.tang 2 years ago committed by GitHub
parent 2de6ba028c
commit 77d260241c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      middleware/logging/logging_test.go

@ -111,7 +111,7 @@ func (d *dummyStringer) String() string {
return "my value"
}
func Test_extractArgs(t *testing.T) {
func TestExtractArgs(t *testing.T) {
if extractArgs(&dummyStringer{field: ""}) != "my value" {
t.Errorf(`The stringified dummyStringer structure must be equal to "my value", %v given`, extractArgs(&dummyStringer{field: ""}))
}
@ -120,3 +120,30 @@ func Test_extractArgs(t *testing.T) {
t.Errorf(`The stringified dummy structure must be equal to "&{field:value}", %v given`, extractArgs(&dummy{field: "value"}))
}
}
func TestExtractError(t *testing.T) {
tests := []struct {
name string
err error
wantLevel log.Level
wantErrStr string
}{
{
"no error", nil, log.LevelInfo, "",
},
{
"error", errors.New("test error"), log.LevelError, "test error",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
level, errStr := extractError(test.err)
if level != test.wantLevel {
t.Errorf("want: %d, got: %d", test.wantLevel, level)
}
if errStr != test.wantErrStr {
t.Errorf("want: %s, got: %s", test.wantErrStr, errStr)
}
})
}
}

Loading…
Cancel
Save