Documentation
¶
Overview ¶
Package celeristest provides test utilities for celeris handlers.
Use NewContext to create a celeris.Context and ResponseRecorder pair, then pass the context to a handler and inspect the recorder.
ctx, rec := celeristest.NewContext("GET", "/hello")
defer celeristest.ReleaseContext(ctx)
err := handler(ctx)
if rec.StatusCode != 200 { ... }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReleaseContext ¶
ReleaseContext returns a celeris.Context to the pool. The context must not be used after this call.
Types ¶
type Option ¶
type Option func(*config)
Option configures a test context.
func WithContentType ¶
WithContentType is a shorthand for WithHeader("content-type", ct).
type ResponseRecorder ¶
type ResponseRecorder struct {
// StatusCode is the HTTP status code written by the handler.
StatusCode int
// Headers are the response headers as key-value pairs.
Headers [][2]string
// Body is the raw response body bytes.
Body []byte
}
ResponseRecorder captures the response written by a handler.
func NewContext ¶
func NewContext(method, path string, opts ...Option) (*celeris.Context, *ResponseRecorder)
NewContext creates a celeris.Context and ResponseRecorder for testing. The returned context has the given method and path, plus any options applied. Call ReleaseContext when done to clean up pooled resources.
func NewContextT ¶
func NewContextT(t *testing.T, method, path string, opts ...Option) (*celeris.Context, *ResponseRecorder)
NewContextT is like NewContext but registers an automatic cleanup with t.Cleanup so callers do not need to defer ReleaseContext manually.
func (*ResponseRecorder) BodyString ¶
func (r *ResponseRecorder) BodyString() string
BodyString returns the response body as a string.
func (*ResponseRecorder) Header ¶
func (r *ResponseRecorder) Header(key string) string
Header returns the value of the first response header matching the given key. Returns empty string if the header is not present.