howmuch/internal/pkg/test/request.go
2024-10-12 17:09:03 +02:00

31 lines
458 B
Go

package test
import (
"io"
"net/http"
"net/http/httptest"
"testing"
)
type Header struct {
Key string
Value string
}
func PerformRequest(
t testing.TB,
r http.Handler,
method, path string,
body io.Reader,
headers ...Header,
) *httptest.ResponseRecorder {
t.Helper()
req := httptest.NewRequest(method, path, body)
for _, h := range headers {
req.Header.Add(h.Key, h.Value)
}
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
return w
}