Documentation
¶
Overview ¶
Package testingtools provides test utilities for v2 handler and middleware testing using the canonical kernel (*request.Context, routing.Transport, endpoint.Executor, telemetry.Sink).
Index ¶
- func AssertResponse(t *TestTransport, expectedStatus int, expectedContentType string) bool
- func DefaultRenderer() renderers.Renderer
- func MappedErrorHandler() routing.ErrorHandler
- func NewTestContext() *request.Context
- func NewTestContextWithMethod(method, path string) *request.Context
- func NewTestExecutor() *endpoint.Executor
- func NewTestExecutorWithSink(sink telemetry.Sink) *endpoint.Executor
- func NewTestWorker() workers.Worker
- type TestTransport
- func (t *TestTransport) Body() []byte
- func (t *TestTransport) Committed() bool
- func (t *TestTransport) ContentType() string
- func (t *TestTransport) Header() http.Header
- func (t *TestTransport) Status() int
- func (t *TestTransport) WriteResponse(status int, contentType string, headers http.Header, body []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertResponse ¶
func AssertResponse(t *TestTransport, expectedStatus int, expectedContentType string) bool
AssertResponse checks that the transport captured the expected response status and content type.
func DefaultRenderer ¶
DefaultRenderer returns the default JSON renderer for tests.
func MappedErrorHandler ¶
func MappedErrorHandler() routing.ErrorHandler
MappedErrorHandler creates a routing.ErrorHandler for tests using the default problem mapper.
func NewTestContext ¶
NewTestContext creates a *request.Context suitable for testing handlers and middleware without a real HTTP framework.
func NewTestContextWithMethod ¶
NewTestContextWithMethod creates a *request.Context with the given HTTP method and path.
func NewTestExecutor ¶
NewTestExecutor creates an endpoint.Executor suitable for testing. It uses a nop telemetry sink and a fresh operation registry.
func NewTestExecutorWithSink ¶
NewTestExecutorWithSink creates an executor with a capturing telemetry sink for verifying telemetry events in tests.
func NewTestWorker ¶
NewTestWorker creates an in-process worker pool for testing async job behavior.
Types ¶
type TestTransport ¶
type TestTransport struct {
// contains filtered or unexported fields
}
TestTransport is a routing.Transport implementation for tests. It captures the response status, content type, headers, and body.
func NewTestTransport ¶
func NewTestTransport() *TestTransport
NewTestTransport creates a fake routing.Transport that captures response writes for assertion in tests.
func (*TestTransport) Body ¶
func (t *TestTransport) Body() []byte
Body returns the response body bytes.
func (*TestTransport) Committed ¶
func (t *TestTransport) Committed() bool
Committed reports whether the response has been written.
func (*TestTransport) ContentType ¶
func (t *TestTransport) ContentType() string
ContentType returns the response Content-Type header.
func (*TestTransport) Header ¶
func (t *TestTransport) Header() http.Header
Header returns the response headers.
func (*TestTransport) Status ¶
func (t *TestTransport) Status() int
Status returns the captured HTTP status code.
func (*TestTransport) WriteResponse ¶
func (t *TestTransport) WriteResponse(status int, contentType string, headers http.Header, body []byte) error
WriteResponse writes the response to the internal recorder.