-
Notifications
You must be signed in to change notification settings - Fork 21
/
filter_test.go
42 lines (36 loc) · 775 Bytes
/
filter_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
package logrus_fluent
import (
"errors"
"fmt"
"testing"
)
func TestFilterError(t *testing.T) {
tests := []struct {
data interface{}
isError bool
}{
{errors.New("error message"), true},
{fmt.Errorf("error message"), true},
{&myError{}, true},
{1, false},
{1.0, false},
{"string value", false},
}
for _, tt := range tests {
target := fmt.Sprintf("%#v", tt)
result := FilterError(tt.data)
switch {
case tt.isError:
err := tt.data.(error)
if result != err.Error() {
t.Errorf("result should be error message: %s", target)
}
default:
if result != tt.data {
t.Errorf("result should be same as the original data: %s", target)
}
}
}
}
type myError struct{}
func (myError) Error() string { return "myError's Error" }