-
Notifications
You must be signed in to change notification settings - Fork 1
/
status_test.go
112 lines (103 loc) · 2.37 KB
/
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
107
108
109
110
111
112
package httpc_test
import (
"net/http"
"testing"
"github.com/jsteenb2/httpc"
)
func TestStatusFuncs(t *testing.T) {
t.Run("single match", func(t *testing.T) {
tests := []struct {
statusFn httpc.StatusFn
statusCode int
}{
{
statusCode: http.StatusOK,
statusFn: httpc.StatusOK(),
},
{
statusCode: http.StatusNoContent,
statusFn: httpc.StatusNoContent(),
},
{
statusCode: http.StatusNotFound,
statusFn: httpc.StatusNotFound(),
},
{
statusCode: http.StatusUnprocessableEntity,
statusFn: httpc.StatusUnprocessableEntity(),
},
{
statusCode: http.StatusInternalServerError,
statusFn: httpc.StatusInternalServerError(),
},
}
for _, tt := range tests {
fn := func(t *testing.T) {
equals(t, true, tt.statusFn(tt.statusCode))
}
t.Run(http.StatusText(tt.statusCode), fn)
}
})
t.Run("in matches", func(t *testing.T) {
tests := []struct {
name string
input []int
}{
{
name: "200s",
input: []int{http.StatusOK, http.StatusCreated, http.StatusAccepted, http.StatusNoContent},
},
{
name: "300s",
input: []int{http.StatusTemporaryRedirect, http.StatusMovedPermanently},
},
{
name: "400s",
input: []int{http.StatusNotFound, http.StatusForbidden, http.StatusUnprocessableEntity},
},
{
name: "500s",
input: []int{http.StatusInternalServerError, http.StatusBadGateway},
},
}
for _, tt := range tests {
fn := func(t *testing.T) {
for _, testcase := range tt.input {
equals(t, true, httpc.StatusIn(tt.input...)(testcase))
}
}
t.Run(tt.name, fn)
}
})
t.Run("not in matches", func(t *testing.T) {
tests := []struct {
name string
input []int
}{
{
name: "200s",
input: []int{http.StatusOK, http.StatusCreated, http.StatusAccepted, http.StatusNoContent},
},
{
name: "300s",
input: []int{http.StatusTemporaryRedirect, http.StatusMovedPermanently},
},
{
name: "400s",
input: []int{http.StatusNotFound, http.StatusForbidden, http.StatusUnprocessableEntity},
},
{
name: "500s",
input: []int{http.StatusInternalServerError, http.StatusBadGateway},
},
}
for _, tt := range tests {
fn := func(t *testing.T) {
for _, testcase := range tt.input {
equals(t, true, httpc.StatusNotIn(tt.input...)(testcase+100))
}
}
t.Run(tt.name, fn)
}
})
}