MCPcopy Index your code
hub / github.com/dnote/dnote / doHTTPReq

Function doHTTPReq

pkg/e2e/sync/testutils.go:217–237  ·  view source on GitHub ↗

doHTTPReq performs an authenticated HTTP request and checks for errors

(t *testing.T, env testEnv, method, path, payload, message string, user database.User)

Source from the content-addressed store, hash-verified

215
216// doHTTPReq performs an authenticated HTTP request and checks for errors
217func 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
240type setupFunc func(t *testing.T, env testEnv, user database.User) map[string]string

Callers 6

apiCreateBookFunction · 0.85
apiPatchBookFunction · 0.85
apiDeleteBookFunction · 0.85
apiCreateNoteFunction · 0.85
apiPatchNoteFunction · 0.85
apiDeleteNoteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected