-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport_test.go
56 lines (49 loc) · 1.22 KB
/
transport_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 httpmock
import (
"net/http"
"net/url"
"testing"
"github.com/stretchr/testify/require"
)
func TestTransportMatch(t *testing.T) {
t.Parallel()
s := Server(t)
uri := s.URL
mocks := load(uri)
New(uri).Reply(204)
u, _ := url.Parse(uri)
req := &http.Request{URL: u}
res, err := NewTransport(mocks).RoundTrip(req)
require.Equal(t, err, nil)
require.Equal(t, res.StatusCode, 204)
require.Equal(t, res.Request, req)
}
func TestTransportCannotMatch(t *testing.T) {
t.Parallel()
s := Server(t)
mocks := load(s.URL)
New(s.URL).Reply(204)
u, _ := url.Parse("http://127.0.0.1:1234")
req := &http.Request{URL: u}
_, err := NewTransport(mocks).RoundTrip(req)
require.Equal(t, err, ErrCannotMatch)
}
//
// func TestTransportNotIntercepting(t *testing.T) {
//
// ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// fmt.Fprintln(w, "Hello, world")
// }))
// defer ts.Close()
//
// New(ts.URL).Reply(200)
// Disable()
//
// u, _ := url.Parse(ts.URL)
// req := &http.Request{URL: u, Header: make(http.Header)}
//
// res, err := NewTransport().RoundTrip(req)
// require.Equal(t, err, nil)
// require.Equal(t, Intercepting(), false)
// require.Equal(t, res.StatusCode, 200)
// }