package main import ( "code.dlmw.ch/dlmw/qv/internal/models" "io" "log/slog" "net/http" "net/http/httptest" "testing" ) func newTestApplication(t *testing.T) *application { return &application{ logger: slog.New(slog.NewTextHandler(io.Discard, nil)), elections: &models.ElectionModel{}, } } type testServer struct { *httptest.Server } func newTestServer(t *testing.T, h http.Handler) *testServer { server := httptest.NewServer(h) return &testServer{server} } func (ts *testServer) post(t *testing.T, urlPath string, body io.Reader) (int, http.Header, string) { res, err := ts.Client().Post(ts.URL+urlPath, "application/json", body) if err != nil { t.Fatal(err) } defer res.Body.Close() responseBody, err := io.ReadAll(res.Body) if err != nil { t.Fatal(err) } return res.StatusCode, res.Header, string(responseBody) }