flowtest

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

flow/testkit/flowtest.go

Package flowtest is the flow-specific test harness. It is built entirely on top of github.com/nexssp/testkit primitives (Trace, GoldenJSON, EventuallyE) plus the flow compiler, so it never touches the kernel and never leaks domain logic back into testkit.

Every helper returns a value that supports chained assertions. The package is designed so a full end-to-end test of a nontrivial flow reads like a paragraph of English, not a wall of setup code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Harness

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

Harness binds a compiled flow to a registry, a trace, and a fake clock. Every helper method runs against this harness.

func New

func New(t testing.TB, dsl string, libs ...action.Library) *Harness

New compiles dsl against the given libraries, installs a Trace on every action, and returns a Harness ready for one or more runs.

func (*Harness) AssertConcurrent

func (h *Harness) AssertConcurrent(workers int)

AssertConcurrent runs the flow concurrently across workers and asserts that (a) every run succeeded, (b) no race was detected by -race, and (c) the trace contains exactly the expected number of executions of every action in the flow.

func (*Harness) AssertMaxAllocs

func (h *Harness) AssertMaxAllocs(n int, budget float64)

AssertMaxAllocs runs the flow n times and asserts that the total allocation count (rough) is under budget. Useful for keeping a hot path zero-alloc as the flow grows.

func (*Harness) Registry

func (h *Harness) Registry() *action.Registry

Registry returns the registry, so callers can look up specific actions.

func (*Harness) Run

func (h *Harness) Run(payload map[string]any) *Run

Run executes the flow with payload and returns a Run.

func (*Harness) Trace

func (h *Harness) Trace() *ktest.Trace

Trace returns the underlying trace for direct assertions.

func (*Harness) WithTimeout

func (h *Harness) WithTimeout(d time.Duration) *Harness

WithTimeout changes the run timeout.

type Run

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

Run captures the outcome of one flow execution.

func (*Run) AssertFast

func (r *Run) AssertFast(d time.Duration) *Run

AssertFast asserts the run finished in less than d.

func (*Run) AssertLayers

func (r *Run) AssertLayers(want int) *Run

AssertLayers asserts that the number of executed layers matches want.

func (*Run) AssertOutput

func (r *Run) AssertOutput(key string, want any) *Run

AssertOutput asserts that outputs[key] equals want, comparing with fmt.Sprintf("%v") so structs, numbers, and strings all work without custom comparators.

func (*Run) Duration

func (r *Run) Duration() time.Duration

Duration returns the wall-clock time of the run.

func (*Run) ExpectFailure

func (r *Run) ExpectFailure() *Run

ExpectFailure fails the test if the flow succeeded.

func (*Run) ExpectSuccess

func (r *Run) ExpectSuccess() *Run

ExpectSuccess fails the test if the flow returned an error.

func (*Run) Golden

func (r *Run) Golden(name string) *Run

Golden writes the whole run to testdata/<name>.golden.json and, on subsequent runs, compares. Use -testkit.update to rewrite.

func (*Run) Output

func (r *Run) Output() map[string]any

Output returns the raw output map.

func (*Run) OutputKey

func (r *Run) OutputKey(key string) any

OutputKey returns the value at key, failing if absent.

func (*Run) Trace

func (r *Run) Trace() *ktest.Trace

Trace returns the shared trace so callers can chain assertions.

Jump to

Keyboard shortcuts

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