forked from ivpusic/httpcheck
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtester_status_test.go
51 lines (47 loc) · 1.09 KB
/
tester_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
package httpcheck
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTester_HasStatus(t *testing.T) {
testdata := []struct {
name string
method string
expected int
want bool
}{
{
name: "OK: expected status 202",
method: http.MethodGet,
expected: http.StatusAccepted,
want: false,
},
{
name: "NG: expected status 200 but got 202",
method: http.MethodGet,
expected: http.StatusOK,
want: true,
},
}
for _, tt := range testdata {
t.Run(tt.name, func(t *testing.T) {
mockT := new(testing.T)
checker := newTestChecker()
checker.Test(mockT, "GET", "/some").
Check().
HasStatus(tt.expected)
assert.Equal(t, tt.want, mockT.Failed())
})
}
}
func TestTester_MustHasStatus(t *testing.T) {
t.Skip("skip this test because it expects failure.")
checker := newTestChecker()
checker.Test(t, "GET", "/some").
Check().
MustHasStatus(111). // ← it requires to be true, but it fails.
Cb(func(r *http.Response) {
t.Fatal("it is expected that this assertion will not be executed.")
})
}