-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
37 lines (32 loc) · 987 Bytes
/
errors_test.go
File metadata and controls
37 lines (32 loc) · 987 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
package ujeebu
import (
"encoding/json"
"strings"
"testing"
)
func TestAPIError_Unmarshal_ErrorCodeNumber(t *testing.T) {
var e APIError
if err := json.Unmarshal([]byte(`{"message":"bad","error_code":404}`), &e); err != nil {
t.Fatalf("unmarshal: %v", err)
}
e.StatusCode = 404
if got := e.errorCodeString(); got != "404" {
t.Fatalf("expected error code '404', got %q", got)
}
if got := e.Error(); !strings.Contains(got, "code: 404") {
t.Fatalf("expected Error() to include code: 404, got %q", got)
}
}
func TestAPIError_Unmarshal_ErrorCodeString(t *testing.T) {
var e APIError
if err := json.Unmarshal([]byte(`{"message":"bad","error_code":"AUTH"}`), &e); err != nil {
t.Fatalf("unmarshal: %v", err)
}
e.StatusCode = 401
if got := e.errorCodeString(); got != "AUTH" {
t.Fatalf("expected error code 'AUTH', got %q", got)
}
if got := e.Error(); !strings.Contains(got, "code: AUTH") {
t.Fatalf("expected Error() to include code: AUTH, got %q", got)
}
}