-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.go
More file actions
39 lines (33 loc) · 766 Bytes
/
Copy pathrequest.go
File metadata and controls
39 lines (33 loc) · 766 Bytes
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
package gostman
import (
"io"
"net/http"
neturl "net/url"
"testing"
log "github.com/sirupsen/logrus"
)
// Request contains all necessary thing to create a Gostman request.
type Request struct {
t *testing.T
client http.Client
method string
url string
params neturl.Values
headers http.Header
body io.Reader
}
// Send sends a request. The testing can be done inside f.
func (r *Request) Send(f func(t *testing.T, req *http.Request, res *http.Response)) {
url := r.url + "?" + r.params.Encode()
req, err := http.NewRequest(r.method, url, r.body)
if err != nil {
log.Fatal(err)
}
req.Header = r.headers
req.Header.Set("Host", req.URL.Host)
res, err := r.client.Do(req)
if err != nil {
log.Fatal(err)
}
f(r.t, req, res)
}