testharness

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 5 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, 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) any

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) any

HandleAsLeader sends a message with IsLeader=true in context.

func (*Harness) Handler

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

Handler implements module.Handler, capturing outputs and metadata writes.

func (*Harness) LeaderHandler

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

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 EmitterAware on the new instance so it can publish from background loops just like a freshly scheduled runner would.

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) any

Reconcile simulates a reconcile event with current metadata.

func (*Harness) ReconcileAsLeader

func (h *Harness) ReconcileAsLeader(ctx context.Context) any

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