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