-
Notifications
You must be signed in to change notification settings - Fork 72
/
errors_test.go
54 lines (50 loc) · 1.34 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
package trello
import (
"bytes"
"io/ioutil"
"net/http"
"strings"
"testing"
)
func TestRateLimitError(t *testing.T) {
rc := ioutil.NopCloser(&bytes.Buffer{})
resp := &http.Response{
Body: rc,
StatusCode: http.StatusTooManyRequests,
}
e := makeHTTPClientError("/url/string", resp)
if !IsRateLimit(e) {
t.Error("Expected rate limit error")
}
if !strings.HasPrefix(e.Error(), "HTTP request failure") {
t.Errorf("Expected error message 'HTTP request failure...', got: '%s'", e.Error())
}
}
func TestNotFoundError(t *testing.T) {
rc := ioutil.NopCloser(&bytes.Buffer{})
resp := &http.Response{
Body: rc,
StatusCode: http.StatusNotFound,
}
e := makeHTTPClientError("/url/string", resp)
if !IsNotFound(e) {
t.Error("Expected not found error")
}
if !strings.HasPrefix(e.Error(), "HTTP request failure") {
t.Errorf("Expected error message 'HTTP request failure...', got: '%s'", e.Error())
}
}
func TestPermissionDeniedError(t *testing.T) {
rc := ioutil.NopCloser(&bytes.Buffer{})
resp := &http.Response{
Body: rc,
StatusCode: http.StatusUnauthorized,
}
e := makeHTTPClientError("/url/string", resp)
if !IsPermissionDenied(e) {
t.Error("Expected not found error")
}
if !strings.HasPrefix(e.Error(), "HTTP request failure") {
t.Errorf("Expected error message 'HTTP request failure...', got: '%s'", e.Error())
}
}