-
Notifications
You must be signed in to change notification settings - Fork 68
/
errors_test.go
82 lines (69 loc) · 1.92 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
70
71
72
73
74
75
76
77
78
79
80
81
82
package bot
import (
"errors"
"testing"
)
func TestTooManyRequestsError(t *testing.T) {
err := &TooManyRequestsError{
Message: "rate limit exceeded",
RetryAfter: 30,
}
expectedErrorMsg := "rate limit exceeded: retry_after 30"
if err.Error() != expectedErrorMsg {
t.Errorf("expected %s, got %s", expectedErrorMsg, err.Error())
}
if !IsTooManyRequestsError(err) {
t.Errorf("expected IsTooManyRequestsError to return true")
}
var genericError error = err
if !IsTooManyRequestsError(genericError) {
t.Errorf("expected IsTooManyRequestsError to return true for generic error type")
}
}
func TestMigrateError(t *testing.T) {
err := &MigrateError{
Message: "chat migrated",
MigrateToChatID: 12345,
}
expectedErrorMsg := "chat migrated: migrate_to_chat_id 12345"
if err.Error() != expectedErrorMsg {
t.Errorf("expected %s, got %s", expectedErrorMsg, err.Error())
}
if !IsMigrateError(err) {
t.Errorf("expected IsMigrateError to return true")
}
var genericError error = err
if !IsMigrateError(genericError) {
t.Errorf("expected IsMigrateError to return true for generic error type")
}
}
func TestStandardErrors(t *testing.T) {
tests := []struct {
err error
expected string
}{
{ErrorForbidden, "forbidden"},
{ErrorBadRequest, "bad request"},
{ErrorUnauthorized, "unauthorized"},
{ErrorTooManyRequests, "too many requests"},
{ErrorNotFound, "not found"},
{ErrorConflict, "conflict"},
}
for _, tt := range tests {
if tt.err.Error() != tt.expected {
t.Errorf("expected %s, got %s", tt.expected, tt.err.Error())
}
}
}
func TestIsTooManyRequestsErrorFalse(t *testing.T) {
err := errors.New("some other error")
if IsTooManyRequestsError(err) {
t.Errorf("expected IsTooManyRequestsError to return false")
}
}
func TestIsMigrateErrorFalse(t *testing.T) {
err := errors.New("some other error")
if IsMigrateError(err) {
t.Errorf("expected IsMigrateError to return false")
}
}