-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors_test.go
More file actions
49 lines (43 loc) · 1021 Bytes
/
Copy patherrors_test.go
File metadata and controls
49 lines (43 loc) · 1021 Bytes
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
package dashamail
import (
"errors"
"testing"
)
func TestAPIError_Error(t *testing.T) {
e := &APIError{Code: 4, Message: "Invalid API key"}
want := "dashamail: API error 4: Invalid API key"
if e.Error() != want {
t.Errorf("Error() = %q, want %q", e.Error(), want)
}
}
func TestAPIError_ErrorsAs(t *testing.T) {
original := &APIError{Code: 10, Message: "test"}
wrapped := error(original)
var target *APIError
if !errors.As(wrapped, &target) {
t.Error("errors.As should match *APIError")
}
if target.Code != 10 {
t.Errorf("Code = %d, want 10", target.Code)
}
}
func TestAPIError_Codes(t *testing.T) {
tests := []struct {
code int
msg string
}{
{0, "OK"},
{1, "Unknown error"},
{4, "Invalid API key"},
{100, "Rate limit exceeded"},
}
for _, tt := range tests {
e := &APIError{Code: tt.code, Message: tt.msg}
if e.Code != tt.code {
t.Errorf("Code = %d, want %d", e.Code, tt.code)
}
if e.Message != tt.msg {
t.Errorf("Message = %q, want %q", e.Message, tt.msg)
}
}
}