testkit

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package testkit provides small helpers for generated runtime integration tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEmitted

func AssertEmitted[E any](t testing.TB, events []contracts.EventEnvelope, category contracts.EventCategory, check func(E))

AssertEmitted finds one captured event with the requested category and type.

func AssertHeader

func AssertHeader(t testing.TB, handler http.Handler, method, requestPath, name, want string)

AssertHeader checks one response header value.

func AssertNoEvents

func AssertNoEvents(t testing.TB, events []contracts.EventEnvelope)

AssertNoEvents fails when a command unexpectedly emitted events.

func AssertStatus

func AssertStatus(t testing.TB, handler http.Handler, method, requestPath, body string, want int)

AssertStatus checks one request's response status.

func CaptureCommandEvents

func CaptureCommandEvents[C, R any](t testing.TB, registry *contracts.Registry, command C) (R, []contracts.EventEnvelope)

CaptureCommandEvents runs a command and fails the test on command errors.

func ContractRegistry

func ContractRegistry(register ...func(*contracts.Registry)) *contracts.Registry

ContractRegistry creates an in-memory registry for contract tests.

func Response

func Response(handler http.Handler, scenario Scenario) *httptest.ResponseRecorder

Response executes one scenario and returns the recorder for custom checks.

func Run

func Run(t testing.TB, handler http.Handler, scenarios []Scenario)

Run executes scenarios against handler.

Types

type Scenario

type Scenario struct {
	Name       string
	Method     string
	Path       string
	Body       string
	Headers    map[string]string
	WantStatus int
	WantHeader map[string]string
}

Scenario describes one HTTP expectation against a generated app handler.

Jump to

Keyboard shortcuts

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