-
Notifications
You must be signed in to change notification settings - Fork 0
/
goverror_test.go
97 lines (91 loc) · 2.04 KB
/
goverror_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package governor
import (
"net/http"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestError(t *testing.T) {
t.Parallel()
assert := require.New(t)
for _, tc := range []struct {
Err error
String string
}{
{
Err: ErrNoLog,
String: "No log",
},
{
Err: ErrUnreachable,
String: "Unreachable code. Invariant violated",
},
{
Err: &ErrorRes{
Status: http.StatusBadRequest,
Code: "test_code",
Message: "test error message",
},
String: "(400) test error message [test_code]",
},
{
Err: &ErrorRes{
Status: http.StatusBadRequest,
Code: "test_code",
Message: "test error message",
},
String: "(400) test error message [test_code]",
},
{
Err: &ErrorTooManyRequests{
RetryAfter: time.Date(1991, time.August, 25, 20, 57, 9, 0, time.UTC),
},
String: "Too many requests. Try again after Sun, 25 Aug 1991 20:57:09 UTC.",
},
{
Err: ErrInvalidConfig,
String: "Invalid config",
},
{
Err: ErrVault,
String: "Failed vault request",
},
{
Err: ErrInvalidClientReq,
String: "Invalid client request",
},
{
Err: ErrSendClientReq,
String: "Failed sending client request",
},
{
Err: ErrInvalidServerRes,
String: "Invalid server response",
},
} {
assert.Equal(tc.String, tc.Err.Error())
}
for _, tc := range []struct {
Err error
String string
}{
{
Err: ErrWithNoLog(nil),
String: "No log",
},
{
Err: ErrWithRes(nil, http.StatusUnauthorized, "another_test_code", "yet another test error message"),
String: "(401) yet another test error message [another_test_code]",
},
{
Err: ErrWithUnreachable(nil, "test unreachable code"),
String: "Unreachable code. Invariant violated",
},
{
Err: ErrWithTooManyRequests(nil, time.Date(1991, time.August, 25, 20, 57, 9, 0, time.UTC), "too_many_test_code", "too many test requests"),
String: "Too many requests. Try again after Sun, 25 Aug 1991 20:57:09 UTC.",
},
} {
assert.Contains(tc.Err.Error(), tc.String)
}
}