Implement file handlers integration tests

This commit is contained in:
2024-11-28 21:18:47 +01:00
parent 91489ca633
commit 3fb40a8817
2 changed files with 260 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ package handlers_test
import (
"bytes"
"encoding/json"
"io"
"net/http/httptest"
"os"
"testing"
@@ -195,3 +196,23 @@ func (h *testHarness) makeRequest(t *testing.T, method, path string, body interf
return rr
}
// makeRequestRaw is a helper function to make HTTP requests with raw body content
func (h *testHarness) makeRequestRaw(t *testing.T, method, path string, body io.Reader, token string, headers map[string]string) *httptest.ResponseRecorder {
t.Helper()
req := httptest.NewRequest(method, path, body)
if token != "" {
req.Header.Set("Authorization", "Bearer "+token)
}
// Add any additional headers
for k, v := range headers {
req.Header.Set(k, v)
}
rr := httptest.NewRecorder()
h.Router.ServeHTTP(rr, req)
return rr
}