testkit

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package testkit provides a canonical harness for module-level tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Controller

func Controller[T any](tb TB, h *Harness, moduleName, controllerName string) T

Controller returns a typed controller or fails the test.

func ControllerE

func ControllerE[T any](h *Harness, moduleName, controllerName string) (T, error)

ControllerE returns a typed controller instance.

func Get

func Get[T any](tb TB, h *Harness, token module.Token) T

Get resolves a typed token or fails the test.

func GetE

func GetE[T any](h *Harness, token module.Token) (T, error)

GetE resolves a typed token.

Types

type ControllerNotFoundError

type ControllerNotFoundError struct {
	Module string
	Name   string
}

ControllerNotFoundError is returned when a controller key is missing in the harness app.

func (*ControllerNotFoundError) Error

func (e *ControllerNotFoundError) Error() string

type Harness

type Harness struct {
	// contains filtered or unexported fields
}

Harness wraps a bootstrapped app for test ergonomics.

func New

func New(tb TB, root module.Module, opts ...Option) *Harness

New bootstraps a test harness and fails the test if bootstrap fails.

func NewE

func NewE(tb TB, root module.Module, opts ...Option) (*Harness, error)

NewE bootstraps a test harness and returns bootstrap errors.

func (*Harness) App

func (h *Harness) App() *kernel.App

App returns the underlying bootstrapped app.

func (*Harness) Close

func (h *Harness) Close() error

Close closes cleanup hooks and closers with background context.

func (*Harness) CloseContext

func (h *Harness) CloseContext(ctx context.Context) error

CloseContext closes cleanup hooks then app closers. Calls are idempotent.

type HarnessCloseError

type HarnessCloseError struct {
	HookErr  error
	CloseErr error
}

HarnessCloseError aggregates cleanup hook and app close errors.

func (*HarnessCloseError) Error

func (e *HarnessCloseError) Error() string

func (*HarnessCloseError) Unwrap

func (e *HarnessCloseError) Unwrap() []error

Unwrap returns both hook and close errors for errors.Is/errors.As matching.

type NilOptionError

type NilOptionError struct {
	Index int
}

NilOptionError is returned when a nil testkit option is passed.

func (*NilOptionError) Error

func (e *NilOptionError) Error() string

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures testkit harness construction.

func WithOverrides

func WithOverrides(overrides ...Override) Option

WithOverrides applies provider overrides for harness bootstrap.

func WithoutAutoClose

func WithoutAutoClose() Option

WithoutAutoClose disables automatic tb.Cleanup registration.

type Override

type Override struct {
	Token   module.Token
	Build   func(module.Resolver) (any, error)
	Cleanup func(context.Context) error
}

Override describes a token-level provider override for tests.

func OverrideBuild

func OverrideBuild(token module.Token, build func(module.Resolver) (any, error)) Override

OverrideBuild returns a dynamic build override.

func OverrideValue

func OverrideValue(token module.Token, value any) Override

OverrideValue returns a static value override.

type TB

type TB interface {
	Helper()
	Fatalf(format string, args ...any)
	Cleanup(func())
}

TB is the minimal test interface required by TestKit helpers.

type TypeAssertionError

type TypeAssertionError struct {
	Target  string
	Actual  string
	Context string
}

TypeAssertionError is returned when a typed helper cannot assert the requested type.

func (*TypeAssertionError) Error

func (e *TypeAssertionError) Error() string

Jump to

Keyboard shortcuts

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