-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse_test.go
56 lines (49 loc) · 928 Bytes
/
response_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
package httpsling_test
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/theopenlane/httpsling"
)
func TestIsSuccess(t *testing.T) {
testCases := []struct {
name string
code int
expected bool
}{
{
name: "OK",
code: http.StatusOK,
expected: true,
},
{
name: "Unauthorized",
code: http.StatusUnauthorized,
expected: false,
},
{
name: "Created",
code: http.StatusCreated,
expected: true,
},
{
name: "InternalServerError",
code: http.StatusInternalServerError,
expected: false,
},
{
name: "BadRequest",
code: http.StatusBadRequest,
expected: false,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
resp := &http.Response{
StatusCode: tc.code,
}
result := httpsling.IsSuccess(resp)
assert.Equal(t, tc.expected, result)
})
}
}