-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy patherrors_test.go
More file actions
75 lines (59 loc) · 1.79 KB
/
Copy patherrors_test.go
File metadata and controls
75 lines (59 loc) · 1.79 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
package maclookup
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// --- HTTPClientError ---
func TestHTTPClientError_Error(t *testing.T) {
inner := errors.New("connection refused")
e := &HTTPClientError{Err: inner}
assert.Equal(t, "connection refused", e.Error())
}
func TestHTTPClientError_Unwrap(t *testing.T) {
inner := errors.New("connection refused")
e := &HTTPClientError{Err: inner}
assert.True(t, errors.Is(e, inner))
}
// --- BadAPIRequest ---
func TestBadAPIRequest_Error(t *testing.T) {
inner := errors.New("mac must be greater than 5 chars")
e := &BadAPIRequest{Err: inner}
assert.Equal(t, "mac must be greater than 5 chars", e.Error())
}
func TestBadAPIRequest_Unwrap(t *testing.T) {
inner := errors.New("mac must be greater than 5 chars")
e := &BadAPIRequest{Err: inner}
assert.True(t, errors.Is(e, inner))
}
// --- BadAPIKey ---
func TestBadAPIKey_Error(t *testing.T) {
inner := errors.New("Unauthorized")
e := &BadAPIKey{Err: inner}
assert.Equal(t, "Unauthorized", e.Error())
}
func TestBadAPIKey_Unwrap(t *testing.T) {
inner := errors.New("Unauthorized")
e := &BadAPIKey{Err: inner}
assert.True(t, errors.Is(e, inner))
}
// --- RateLimitsExceeded ---
func TestRateLimitsExceeded_Error(t *testing.T) {
reset := time.Date(2024, 1, 15, 12, 0, 0, 0, time.UTC)
e := &RateLimitsExceeded{Limit: 100, Reset: reset}
msg := e.Error()
assert.Contains(t, msg, "100")
assert.Contains(t, msg, "2024-01-15T12:00:00Z")
}
// --- BadAPIResponse ---
func TestBadAPIResponse_Error(t *testing.T) {
inner := errors.New("invalid json")
e := &BadAPIResponse{Err: inner}
assert.Equal(t, "invalid json", e.Error())
}
func TestBadAPIResponse_Unwrap(t *testing.T) {
inner := errors.New("invalid json")
e := &BadAPIResponse{Err: inner}
assert.True(t, errors.Is(e, inner))
}