Documentation
¶
Overview ¶
Package echotest builds echo contexts for handler unit tests so each test states only what differs: method, target, body, and the occasional header or path value.
Index ¶
- func Decode[T any](t testing.TB, rec *httptest.ResponseRecorder) T
- func Get(t testing.TB, target string, opts ...Option) (*echo.Context, *httptest.ResponseRecorder)
- func Post(t testing.TB, target string, body any, opts ...Option) (*echo.Context, *httptest.ResponseRecorder)
- func Request(t testing.TB, method, target string, body any, opts ...Option) (*echo.Context, *httptest.ResponseRecorder)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
func Decode[T any](t testing.TB, rec *httptest.ResponseRecorder) T
Decode unmarshals the recorded JSON response body into T, failing the test when it is not valid JSON for T.
func Post ¶
func Post(t testing.TB, target string, body any, opts ...Option) (*echo.Context, *httptest.ResponseRecorder)
Post is Request for a POST with a JSON body.
func Request ¶
func Request(t testing.TB, method, target string, body any, opts ...Option) (*echo.Context, *httptest.ResponseRecorder)
Request builds an echo context and recorder for a handler call.
body may be nil (no body), a string or []byte (sent verbatim), an io.Reader, or any other value, which is JSON-encoded. A non-nil body gets a JSON Content-Type unless WithContentType overrides it.
Types ¶
type Option ¶
type Option func(*settings)
Option adjusts the request or context built by Request.
func WithContentType ¶
WithContentType overrides the Content-Type set for a non-nil body.
func WithPathValue ¶
WithPathValue binds a route parameter (c.Param) for the handler.