feat: make the request test helper public

This commit is contained in:
Muyao CHEN
2024-10-12 17:07:24 +02:00
parent a3c2ade9fb
commit 9b6282a101
2 changed files with 36 additions and 22 deletions

View File

@ -0,0 +1,27 @@
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
}