Repository navigation
Expand file tree
/
Copy patherror_test.go
More file actions
81 lines (70 loc) · 2.38 KB
/
Copy patherror_test.go
File metadata and controls
81 lines (70 loc) · 2.38 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
package tempmail
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestHTTPError_Error(t *testing.T) {
httpErr := &HTTPError{
Response: &http.Response{StatusCode: http.StatusBadRequest},
ErrorDetails: HTTPErrorError{
Type: "request_error",
Code: "not_found",
Detail: "The requested resource was not found",
},
Meta: HTTPErrorMeta{
RequestID: "req_123456789",
},
}
expected := "status 400, error type: request_error, code: not_found, detail: The requested resource was not found"
assert.Equal(t, expected, httpErr.Error())
}
func TestHTTPError_Format(t *testing.T) {
httpErr := &HTTPError{
Response: &http.Response{StatusCode: http.StatusBadRequest},
ErrorDetails: HTTPErrorError{
Type: "request_error",
Code: "not_found",
Detail: "The requested resource was not found",
},
Meta: HTTPErrorMeta{
RequestID: "req_123456789",
},
}
t.Run("format with %s", func(t *testing.T) {
result := fmt.Sprintf("%s", httpErr)
expected := "status 400, error type: request_error, code: not_found, detail: The requested resource was not found"
assert.Equal(t, expected, result)
})
t.Run("format with %v", func(t *testing.T) {
result := fmt.Sprintf("%v", httpErr)
expected := "status 400, error type: request_error, code: not_found, detail: The requested resource was not found"
assert.Equal(t, expected, result)
})
t.Run("format with %+v", func(t *testing.T) {
result := fmt.Sprintf("%+v", httpErr)
expected := "status 400, error type: request_error, code: not_found, detail: The requested resource was not found, request_id: req_123456789"
assert.Equal(t, expected, result)
})
t.Run("format with %q", func(t *testing.T) {
result := fmt.Sprintf("%q", httpErr)
expected := "\"status 400, error type: request_error, code: not_found, detail: The requested resource was not found\""
assert.Equal(t, expected, result)
})
}
func TestHTTPError_fullError(t *testing.T) {
httpErr := &HTTPError{
Response: &http.Response{StatusCode: http.StatusBadGateway},
ErrorDetails: HTTPErrorError{
Type: "api_error",
Code: "internal_error",
Detail: "Internal server error",
},
Meta: HTTPErrorMeta{
RequestID: "req_987654321",
},
}
expected := "status 502, error type: api_error, code: internal_error, detail: Internal server error, request_id: req_987654321"
assert.Equal(t, expected, httpErr.fullError())
}