testingtools

package
v2.0.0-...-0e31793 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 12 Imported by: 0

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

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

func DefaultRenderer() renderers.Renderer

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

func NewTestContext() *request.Context

NewTestContext creates a *request.Context suitable for testing handlers and middleware without a real HTTP framework.

func NewTestContextWithMethod

func NewTestContextWithMethod(method, path string) *request.Context

NewTestContextWithMethod creates a *request.Context with the given HTTP method and path.

func NewTestExecutor

func NewTestExecutor() *endpoint.Executor

NewTestExecutor creates an endpoint.Executor suitable for testing. It uses a nop telemetry sink and a fresh operation registry.

func NewTestExecutorWithSink

func NewTestExecutorWithSink(sink telemetry.Sink) *endpoint.Executor

NewTestExecutorWithSink creates an executor with a capturing telemetry sink for verifying telemetry events in tests.

func NewTestWorker

func NewTestWorker() workers.Worker

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL