Total Lines | 26 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package helpers |
||
2 | |||
3 | import ( |
||
4 | "net/http" |
||
5 | "net/http/httptest" |
||
6 | ) |
||
7 | |||
8 | // MakeTestServer creates an api server for testing |
||
9 | func MakeTestServer(responseCode int, body string) *httptest.Server { |
||
10 | return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { |
||
11 | res.WriteHeader(responseCode) |
||
12 | _, err := res.Write([]byte(body)) |
||
13 | if err != nil { |
||
14 | panic(err) |
||
15 | } |
||
16 | })) |
||
17 | } |
||
18 | |||
19 | // MakeRequestCapturingTestServer creates an api server that captures the request object |
||
20 | func MakeRequestCapturingTestServer(responseCode int, body string, request *http.Request) *httptest.Server { |
||
21 | return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { |
||
22 | *request = *req |
||
23 | res.WriteHeader(responseCode) |
||
24 | _, err := res.Write([]byte(body)) |
||
25 | if err != nil { |
||
26 | panic(err) |
||
27 | } |
||
30 |