diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-11 17:52:29 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-11 17:52:29 -0600 |
| commit | ff15873b766f5be308c9967859bfeb7da7cfa21a (patch) | |
| tree | 5a3799dda610dc6fd7bda3adeab931fb60e986a0 /pkg/test/test.go | |
| parent | 6d525bb541230c707a160ef670449b7588abf43b (diff) | |
refactor: split routes to separate controller files
Diffstat (limited to 'pkg/test/test.go')
| -rw-r--r-- | pkg/test/test.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/pkg/test/test.go b/pkg/test/test.go index a93759e..54712f1 100644 --- a/pkg/test/test.go +++ b/pkg/test/test.go @@ -1,12 +1,14 @@ package test import ( + "bytes" "context" "io" "net/http" "net/http/httptest" "github.com/xlgmokha/x/pkg/serde" + "github.com/xlgmokha/x/pkg/x" ) type RequestOption func(*http.Request) *http.Request @@ -34,6 +36,12 @@ func WithRequestHeader(key, value string) RequestOption { } } +func WithContentType[T any](item T, mediaType serde.MediaType) RequestOption { + body := bytes.NewBuffer(nil) + x.Check(serde.To[T](body, item, mediaType)) + return WithRequestBody(io.NopCloser(body)) +} + func WithRequestBody(body io.ReadCloser) RequestOption { return func(r *http.Request) *http.Request { r.Body = body |
