doHTTPReq performs an authenticated HTTP request and checks for errors
(t *testing.T, env testEnv, method, path, payload, message string, user database.User)
| 215 | |
| 216 | // doHTTPReq performs an authenticated HTTP request and checks for errors |
| 217 | func doHTTPReq(t *testing.T, env testEnv, method, path, payload, message string, user database.User) *http.Response { |
| 218 | apiEndpoint := fmt.Sprintf("%s/api", env.Server.URL) |
| 219 | endpoint := fmt.Sprintf("%s%s", apiEndpoint, path) |
| 220 | |
| 221 | req, err := http.NewRequest(method, endpoint, strings.NewReader(payload)) |
| 222 | if err != nil { |
| 223 | panic(errors.Wrap(err, "constructing http request")) |
| 224 | } |
| 225 | |
| 226 | res := apitest.HTTPAuthDo(t, env.ServerDB, req, user) |
| 227 | if res.StatusCode >= 400 { |
| 228 | bs, err := io.ReadAll(res.Body) |
| 229 | if err != nil { |
| 230 | panic(errors.Wrap(err, "parsing response body for error")) |
| 231 | } |
| 232 | |
| 233 | t.Errorf("%s. HTTP status %d. Message: %s", message, res.StatusCode, string(bs)) |
| 234 | } |
| 235 | |
| 236 | return res |
| 237 | } |
| 238 | |
| 239 | // setupFunc is a function that sets up test data and returns IDs for assertions |
| 240 | type setupFunc func(t *testing.T, env testEnv, user database.User) map[string]string |
no outgoing calls
no test coverage detected