Conditions | 4 |
Total Lines | 21 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | package helpers |
||
23 | func MakeRequestCapturingTestServer(responseCode int, responses [][]byte, requests *[]*http.Request) *httptest.Server { |
||
24 | index := 0 |
||
25 | return httptest.NewServer(http.HandlerFunc(func(responseWriter http.ResponseWriter, request *http.Request) { |
||
26 | clonedRequest := request.Clone(context.Background()) |
||
27 | |||
28 | // clone body |
||
29 | body, err := io.ReadAll(request.Body) |
||
30 | if err != nil { |
||
31 | panic(err) |
||
32 | } |
||
33 | request.Body = io.NopCloser(bytes.NewReader(body)) |
||
34 | clonedRequest.Body = io.NopCloser(bytes.NewReader(body)) |
||
35 | |||
36 | *requests = append(*requests, clonedRequest) |
||
37 | |||
38 | responseWriter.WriteHeader(responseCode) |
||
39 | _, err = responseWriter.Write(responses[index]) |
||
40 | if err != nil { |
||
41 | panic(err) |
||
42 | } |
||
43 | index++ |
||
44 | })) |
||
46 |