-
Notifications
You must be signed in to change notification settings - Fork 59
/
errors_test.go
69 lines (64 loc) · 1.15 KB
/
errors_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
package luno
import (
"fmt"
"testing"
)
func TestError(t *testing.T) {
err := Error{
Code: "ErrFoo",
Message: "Example error message!",
}
if err.Error() != "Example error message! (ErrFoo)" {
t.Errorf("Unexpected error formatting")
}
if err.ErrCode() != "ErrFoo" {
t.Errorf("Unexpected error code")
}
}
func TestIsErrorCode(t *testing.T) {
testCases := []struct {
name string
err error
code string
exp bool
}{
{
name: "nil error",
err: nil,
code: "ErrFoo",
exp: false,
},
{
name: "luno error with code present",
err: Error{
Code: "ErrFoo",
Message: "example error message",
},
code: "ErrFoo",
exp: true,
},
{
name: "luno error with different code",
err: Error{
Code: "ErrBar",
Message: "example error message",
},
code: "ErrFoo",
exp: false,
},
{
name: "string error",
err: fmt.Errorf("normal error"),
code: "ErrFoo",
exp: false,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
actual := IsErrorCode(tc.err, tc.code)
if tc.exp != actual {
t.Errorf("Expected %t but got %t", tc.exp, actual)
}
})
}
}