-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
100 lines (89 loc) · 2.19 KB
/
errors_test.go
File metadata and controls
100 lines (89 loc) · 2.19 KB
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
98
99
100
package cloudlayer
import (
"errors"
"fmt"
"testing"
)
func TestAPIError_Error(t *testing.T) {
err := &APIError{
StatusCode: 400,
StatusText: "Bad Request",
Message: "invalid html field",
RequestPath: "/html/pdf",
RequestMethod: "POST",
}
s := err.Error()
if s == "" {
t.Error("Error() returned empty string")
}
}
func TestAuthError_ErrorsAs(t *testing.T) {
err := &AuthError{APIError: APIError{StatusCode: 401, Message: "unauthorized"}}
var authErr *AuthError
if !errors.As(err, &authErr) {
t.Error("errors.As should match *AuthError")
}
// AuthError embeds APIError — access the embedded fields directly
if authErr.StatusCode != 401 {
t.Errorf("StatusCode = %d", authErr.StatusCode)
}
if authErr.Message != "unauthorized" {
t.Errorf("Message = %q", authErr.Message)
}
}
func TestRateLimitError_RetryAfter(t *testing.T) {
retryAfter := 30
err := &RateLimitError{
APIError: APIError{StatusCode: 429, Message: "rate limited"},
RetryAfter: &retryAfter,
}
s := err.Error()
if s == "" {
t.Error("Error() returned empty string")
}
if err.RetryAfter == nil || *err.RetryAfter != 30 {
t.Errorf("RetryAfter = %v", err.RetryAfter)
}
}
func TestNetworkError_Unwrap(t *testing.T) {
inner := fmt.Errorf("connection refused")
err := &NetworkError{
Message: "network error",
Err: inner,
}
if !errors.Is(err, inner) {
t.Error("errors.Is should find inner error")
}
}
func TestValidationError_Error(t *testing.T) {
err := &ValidationError{Field: "url", Message: "url must not be empty"}
s := err.Error()
if s == "" {
t.Error("Error() returned empty string")
}
}
func TestValidationError_NoField(t *testing.T) {
err := &ValidationError{Message: "something is wrong"}
s := err.Error()
if s == "" {
t.Error("Error() returned empty string")
}
}
func TestConfigError_Error(t *testing.T) {
err := &ConfigError{Message: "apiKey must not be empty"}
s := err.Error()
if s == "" {
t.Error("Error() returned empty string")
}
}
func TestTimeoutError_Error(t *testing.T) {
err := &TimeoutError{
Timeout: 30000,
RequestPath: "/jobs/123",
RequestMethod: "GET",
}
s := err.Error()
if s == "" {
t.Error("Error() returned empty string")
}
}