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

28 lines
420 B
Go

package test
import (
"io"
"net/http"
"net/http/httptest"
)
type Header struct {
Key string
Value string
}
func PerformRequest(
r http.Handler,
method, path string,
body io.Reader,
headers ...Header,
) *httptest.ResponseRecorder {
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
}