-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmock_test.go
58 lines (44 loc) · 1.19 KB
/
mock_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
package mock
import (
"testing"
"github.com/nbio/st"
"gopkg.in/h2non/gentleman.v2"
)
func TestMock(t *testing.T) {
defer Disable()
New("http://foo.com").Reply(204).SetHeader("Server", "gock")
req := gentleman.NewRequest()
req.Use(Plugin)
req.SetHeader("foo", "bar")
req.URL("http://foo.com")
res, err := req.Send()
st.Expect(t, err, nil)
st.Expect(t, res.Ok, true)
st.Expect(t, res.StatusCode, 204)
st.Expect(t, res.Header.Get("Server"), "gock")
}
func TestMockMatchHeader(t *testing.T) {
defer Disable()
New("http://foo.com").MatchHeader("foo", "bar").Reply(204).SetHeader("Server", "gock")
req := gentleman.NewRequest()
req.Use(Plugin)
req.SetHeader("foo", "bar")
req.URL("http://foo.com")
res, err := req.Send()
st.Expect(t, err, nil)
st.Expect(t, res.Ok, true)
st.Expect(t, res.StatusCode, 204)
st.Expect(t, res.Header.Get("Server"), "gock")
}
func TestMockError(t *testing.T) {
defer Disable()
New("http://bar.com").Reply(204).SetHeader("Server", "gock")
req := gentleman.NewRequest()
req.Use(Plugin)
req.SetHeader("foo", "bar")
req.URL("http://foo.com")
res, err := req.Send()
st.Reject(t, err, nil)
st.Expect(t, res.Ok, false)
st.Expect(t, res.StatusCode, 0)
}