testharness

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Harness

type Harness struct {
	Metadata map[string]string
	Outputs  []PortMsg
	// contains filtered or unexported fields
}

Harness wraps a component for testing. Captures all port outputs and manages metadata persistence.

func New

func New(c module.Component) *Harness

New creates a harness for the given component instance. The harness mirrors the scheduler's capability injection so components written against the new lifecycle interfaces (OnSettings, OnReconcile, OnControl, OnEmitter, OnState, etc.) work in tests the same way they do in the runner.

func (*Harness) Handle

func (h *Harness) Handle(ctx context.Context, port string, msg any) module.Result

Handle sends a message to the component on the given port. For system ports, dispatches through the matching capability interface when the component implements one (mirroring scheduler.Update's Phase 1). For other ports, falls through to Component.Handle.

func (*Harness) HandleAsLeader

func (h *Harness) HandleAsLeader(ctx context.Context, port string, msg any) module.Result

HandleAsLeader sends a message with IsLeader=true in context.

func (*Harness) Handler

func (h *Harness) Handler(ctx context.Context, port string, data any) module.Result

Handler implements module.Handler, capturing outputs and metadata writes. Reconcile-port updaters are applied to both h.Metadata (legacy hand-rolled access) and the fake K8s client (so State.Get sees them).

func (*Harness) LeaderHandler

func (h *Harness) LeaderHandler(ctx context.Context, port string, data any) module.Result

LeaderHandler returns a handler with IsLeader=true in context.

func (*Harness) NewPod

func (h *Harness) NewPod() *Harness

NewPod simulates a pod restart: fresh component instance, same metadata. Reinjects all SDK capabilities on the new instance so it behaves like a freshly scheduled runner.

func (*Harness) PortOutputs

func (h *Harness) PortOutputs(port string) []any

PortOutputs returns all data sent to the given port.

func (*Harness) Ports

func (h *Harness) Ports() []module.Port

Ports returns the component's current port definitions.

func (*Harness) Reconcile

func (h *Harness) Reconcile(ctx context.Context) module.Result

Reconcile simulates a reconcile event with current metadata.

func (*Harness) ReconcileAsLeader

func (h *Harness) ReconcileAsLeader(ctx context.Context) module.Result

ReconcileAsLeader simulates a reconcile with IsLeader=true.

func (*Harness) Reset

func (h *Harness) Reset()

Reset clears captured outputs (but keeps metadata).

type PortMsg

type PortMsg struct {
	Port string
	Data any
}

PortMsg captures a single output sent by a component via handler()

Jump to

Keyboard shortcuts

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