-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
response_fluent_status_test.go
106 lines (100 loc) · 3.11 KB
/
response_fluent_status_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package fastshot
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestResponseFluentStatus(t *testing.T) {
tests := []struct {
name string
statusCode int
expectedCode int
expectedText string
expectedInformation bool
expectedSuccess bool
expectedRedirection bool
expectedClientError bool
expectedServerError bool
expectedOK bool
expectedNotFound bool
expectedUnauthorized bool
expectedForbidden bool
expectedError bool
}{
{
name: "200 OK",
statusCode: http.StatusOK,
expectedCode: 200,
expectedText: "[200] OK",
expectedInformation: false,
expectedSuccess: true,
expectedRedirection: false,
expectedClientError: false,
expectedServerError: false,
expectedOK: true,
expectedNotFound: false,
expectedUnauthorized: false,
expectedForbidden: false,
expectedError: false,
},
{
name: "404 Not Found",
statusCode: http.StatusNotFound,
expectedCode: 404,
expectedText: "[404] Not Found",
expectedInformation: false,
expectedSuccess: false,
expectedRedirection: false,
expectedClientError: true,
expectedServerError: false,
expectedOK: false,
expectedNotFound: true,
expectedUnauthorized: false,
expectedForbidden: false,
expectedError: true,
},
{
name: "500 Internal Server Error",
statusCode: http.StatusInternalServerError,
expectedCode: 500,
expectedText: "[500] Internal Server Error",
expectedInformation: false,
expectedSuccess: false,
expectedRedirection: false,
expectedClientError: false,
expectedServerError: true,
expectedOK: false,
expectedNotFound: false,
expectedUnauthorized: false,
expectedForbidden: false,
expectedError: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Arrange
response := &Response{
rawResponse: &http.Response{StatusCode: tt.statusCode},
status: &ResponseFluentStatus{
response: &http.Response{StatusCode: tt.statusCode},
},
}
// Act
result := response.Status()
// Assert
assert.Equal(t, tt.expectedCode, result.Code())
assert.Equal(t, tt.expectedText, result.Text())
assert.Equal(t, tt.expectedCode, response.Raw().StatusCode)
assert.Equal(t, tt.expectedInformation, result.Is1xxInformational())
assert.Equal(t, tt.expectedSuccess, result.Is2xxSuccessful())
assert.Equal(t, tt.expectedRedirection, result.Is3xxRedirection())
assert.Equal(t, tt.expectedClientError, result.Is4xxClientError())
assert.Equal(t, tt.expectedServerError, result.Is5xxServerError())
assert.Equal(t, tt.expectedOK, result.IsOK())
assert.Equal(t, tt.expectedNotFound, result.IsNotFound())
assert.Equal(t, tt.expectedUnauthorized, result.IsUnauthorized())
assert.Equal(t, tt.expectedForbidden, result.IsForbidden())
assert.Equal(t, tt.expectedError, result.IsError())
})
}
}