feat: make the request test helper public
This commit is contained in:
27
internal/pkg/test/request.go
Normal file
27
internal/pkg/test/request.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user