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 ¶
- type Harness
- type Run
- func (r *Run) AssertFast(d time.Duration) *Run
- func (r *Run) AssertLayers(want int) *Run
- func (r *Run) AssertOutput(key string, want any) *Run
- func (r *Run) Duration() time.Duration
- func (r *Run) ExpectFailure() *Run
- func (r *Run) ExpectSuccess() *Run
- func (r *Run) Golden(name string) *Run
- func (r *Run) Output() map[string]any
- func (r *Run) OutputKey(key string) any
- func (r *Run) Trace() *ktest.Trace
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 ¶
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 ¶
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 ¶
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.
type Run ¶
type Run struct {
// contains filtered or unexported fields
}
Run captures the outcome of one flow execution.
func (*Run) AssertFast ¶
AssertFast asserts the run finished in less than d.
func (*Run) AssertLayers ¶
AssertLayers asserts that the number of executed layers matches want.
func (*Run) AssertOutput ¶
AssertOutput asserts that outputs[key] equals want, comparing with fmt.Sprintf("%v") so structs, numbers, and strings all work without custom comparators.
func (*Run) ExpectFailure ¶
ExpectFailure fails the test if the flow succeeded.
func (*Run) ExpectSuccess ¶
ExpectSuccess fails the test if the flow returned an error.
func (*Run) Golden ¶
Golden writes the whole run to testdata/<name>.golden.json and, on subsequent runs, compares. Use -testkit.update to rewrite.