helpers

package
v0.0.0-...-84843ee Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package helpers provides additional testing helper functions

Index

Constants

View Source
const (
	// CallbackBaseURL is the base of the webhook URLs test engines hand to async HTTP steps
	CallbackBaseURL = "http://localhost:8080"

	// CallbackSecret is the callback secret of work that SeedStartedWork stores
	CallbackSecret = "test-secret"

	// AgentWorkerURL is the worker test engines dispatch every agent provider to
	AgentWorkerURL = "http://localhost:1"
)

Variables

View Source
var (
	ErrInvalidSeedFlowStatus = errors.New("invalid seeded flow status")
)

Functions

func Matcher

func Matcher() api.Matcher

Matcher returns a match evaluator backed by a new local script registry for use in tests that don't have an engine instance

func NewScriptStep

func NewScriptStep(id api.StepID, language, src string, outputs ...api.Name) *api.Step

NewScriptStep creates a script step with the given language, code, and output attributes

func NewSimpleStep

func NewSimpleStep(id api.StepID) *api.Step

NewSimpleStep creates a minimal HTTP step with the specified ID

func NewStepWithOutputs

func NewStepWithOutputs(id api.StepID, outputs ...api.Name) *api.Step

NewStepWithOutputs creates an HTTP step that produces the specified output attributes

func NewStepWithPredicate

func NewStepWithPredicate(id api.StepID, lang, src string, outputs ...api.Name) *api.Step

NewStepWithPredicate creates an HTTP step with a predicate script that determines whether the step should execute

func NewTestStep

func NewTestStep() *api.Step

NewTestStep creates a basic HTTP step for testing with required, optional, and output attributes

func NewTestStepWithArgs

func NewTestStepWithArgs(required []api.Name, optional []api.Name) *api.Step

NewTestStepWithArgs creates an HTTP step with the specified required and optional input arguments

func WaitForFlowExists

func WaitForFlowExists(t *testing.T, eng *engine.Engine, fid api.FlowID) api.FlowState

WaitForFlowExists waits for a flow state to become readable

func WaitForFlowState

func WaitForFlowState(t *testing.T, eng *engine.Engine, q FlowStateQuery) api.FlowState

WaitForFlowState waits for a flow state accepted by query.Accept

func WaitForTerminalFlowState

func WaitForTerminalFlowState(t *testing.T, eng *engine.Engine, fid api.FlowID) api.FlowState

WaitForTerminalFlowState waits for a flow to reach a terminal state

func WithEngine

func WithEngine(t *testing.T, fn func(*engine.Engine))

WithEngine creates a test engine, executes the provided function with it, and ensures cleanup happens automatically

func WithEngineDeps

func WithEngineDeps(
	t *testing.T, overrides engine.Dependencies, fn func(*engine.Engine),
)

WithEngineDeps creates a test engine with dependency overrides and ensures cleanup automatically

func WithStartedEngine

func WithStartedEngine(t *testing.T, fn func(*engine.Engine))

WithStartedEngine creates a test engine, starts it, executes the provided function with the engine, and ensures cleanup happens automatically

func WithTestBackend

func WithTestBackend(
	t *testing.T, b timebox.Backend, fn func(*TestEngineEnv),
)

WithTestBackend creates a test engine environment whose engines share the provided backend, so a test can inject faults into its writes

func WithTestEnv

func WithTestEnv(t *testing.T, fn func(*TestEngineEnv))

WithTestEnv creates a test engine environment, executes the provided function with it, and ensures cleanup happens automatically

func WithTestEnvDeps

func WithTestEnvDeps(
	t *testing.T, overrides engine.Dependencies, fn func(*TestEngineEnv),
)

WithTestEnvDeps creates a test engine environment with dependency overrides and ensures cleanup happens automatically

Types

type FlowEvent

type FlowEvent struct {
	Data any
	Type api.EventType
}

type FlowStateQuery

type FlowStateQuery struct {
	Accept  func(api.FlowState) bool
	FlowID  api.FlowID
	Timeout time.Duration
}

FlowStateQuery groups the parameters for WaitForFlowState

type MockClient

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

MockClient is a simple mock implementation of client.Client for testing

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a mock HTTP client that allows setting responses and errors for specific step IDs

func (*MockClient) ClearError

func (c *MockClient) ClearError(sid api.StepID)

ClearError removes any configured error for a step

func (*MockClient) ClearInvoke

func (c *MockClient) ClearInvoke(sid api.StepID)

ClearInvoke removes a custom handler for a step

func (*MockClient) Compensate

func (c *MockClient) Compensate(st *api.Step, args api.Args, md api.Metadata) error

Compensate records the compensate invocation and returns any configured error

func (*MockClient) GetInvocations

func (c *MockClient) GetInvocations() []api.StepID

GetInvocations returns the list of step IDs that were invoked

func (*MockClient) Invoke

func (c *MockClient) Invoke(st *api.Step, args api.Args, md api.Metadata) (api.Args, error)

Invoke records the invocation and returns the configured response or error

func (*MockClient) LastMetadata

func (c *MockClient) LastMetadata(sid api.StepID) api.Metadata

LastMetadata returns the most recent metadata passed for a step invocation

func (*MockClient) SetCompError

func (c *MockClient) SetCompError(sid api.StepID, err error)

SetCompError configures the mock to return an error on compensation

func (*MockClient) SetCompensate

func (c *MockClient) SetCompensate(sid api.StepID, fn MockCompensate)

SetCompensate configures a custom compensation handler for a step

func (*MockClient) SetError

func (c *MockClient) SetError(sid api.StepID, err error)

SetError configures the mock to return an error for a step

func (*MockClient) SetInvoke

func (c *MockClient) SetInvoke(sid api.StepID, fn MockInvoke)

SetInvoke configures a custom invocation handler for a step

func (*MockClient) SetResponse

func (c *MockClient) SetResponse(sid api.StepID, outputs api.Args)

SetResponse configures the mock to return specific outputs for a step

func (*MockClient) WaitForInvocation

func (c *MockClient) WaitForInvocation(sid api.StepID, timeout time.Duration) bool

WaitForInvocation blocks until a step is invoked or the timeout expires

func (*MockClient) WasInvoked

func (c *MockClient) WasInvoked(sid api.StepID) bool

WasInvoked returns whether a specific step was invoked

type MockCompensate

type MockCompensate func(*api.Step, api.Args, api.Metadata) error

type MockInvoke

type MockInvoke func(*api.Step, api.Args, api.Metadata) (api.Args, error)

type TestEngineEnv

type TestEngineEnv struct {
	T          *testing.T
	Engine     *engine.Engine
	MockClient *MockClient
	Config     *config.Config
	EventHub   *event.Hub
	Cleanup    func()
	// contains filtered or unexported fields
}

TestEngineEnv holds all the components needed for engine testing

func NewTestEngine

func NewTestEngine(t *testing.T) *TestEngineEnv

NewTestEngine creates a fully configured test engine environment with an in-memory Timebox backend and mock HTTP client

func NewTestEngineWithDeps

func NewTestEngineWithDeps(t *testing.T, overrides engine.Dependencies) *TestEngineEnv

NewTestEngineWithDeps creates a test engine with dependency overrides

func (*TestEngineEnv) AppendEvents

func (e *TestEngineEnv) AppendEvents(
	id timebox.AggregateID, atSeq int64, evs ...*timebox.Event,
) error

AppendEvents appends raw events to the shared test store

func (*TestEngineEnv) ConflictFired

func (e *TestEngineEnv) ConflictFired() bool

ConflictFired reports whether an armed conflict was actually injected

func (*TestEngineEnv) ConflictOnNextAppend

func (e *TestEngineEnv) ConflictOnNextAppend(fid api.FlowID)

ConflictOnNextAppend makes the next append for a flow lose an optimistic- concurrency race, so the executor discards that attempt and runs the command again. Pair it with ConflictFired to confirm it took effect

func (*TestEngineEnv) Dependencies

func (e *TestEngineEnv) Dependencies() engine.Dependencies

Dependencies returns a valid dependency bundle for constructing an engine

func (*TestEngineEnv) FlowTags

func (e *TestEngineEnv) FlowTags(fid api.FlowID) ([]string, error)

FlowTags returns the tags currently indexed for a flow, sorted

func (*TestEngineEnv) NewEngineInstance

func (e *TestEngineEnv) NewEngineInstance() (*engine.Engine, error)

NewEngineInstance creates a new engine instance sharing the same backend and mock client. Used to simulate process restart after crash

func (*TestEngineEnv) NewEngineWithConfig

func (e *TestEngineEnv) NewEngineWithConfig(
	cfg *config.Config, deps engine.Dependencies,
) (*engine.Engine, func(), error)

NewEngineWithConfig creates a new engine instance with the given configuration and subscribes it to the shared committed-event stream

func (*TestEngineEnv) OpenBackend

func (e *TestEngineEnv) OpenBackend(pub timebox.Publisher) (timebox.Backend, error)

OpenBackend hands an engine the backend every engine in this test shares, subscribing it to the commits all of them make

func (*TestEngineEnv) RaiseFlowEvents

func (e *TestEngineEnv) RaiseFlowEvents(fid api.FlowID, evs ...FlowEvent) error

RaiseFlowEvents appends flow events via the executor

func (*TestEngineEnv) ScheduleKeys

func (e *TestEngineEnv) ScheduleKeys() (util.Set[timebox.ScheduleKey], error)

ScheduleKeys loads the keys of every active schedule, a page at a time

func (*TestEngineEnv) SeedFlow

func (e *TestEngineEnv) SeedFlow(fid api.FlowID, status api.FlowStatus, tags api.Tags) error

SeedFlow stores a minimal valid flow history for state/query fixtures

func (*TestEngineEnv) SeedStartedWork

func (e *TestEngineEnv) SeedStartedWork(
	fs api.FlowStep, pl *api.ExecutionPlan, tkn api.Token,
) error

SeedStartedWork stores a flow whose single work item has been claimed, the state a node leaves behind when it dies mid-attempt

func (*TestEngineEnv) SubscribeCommitted

func (e *TestEngineEnv) SubscribeCommitted(fn timebox.Publisher) func()

SubscribeCommitted registers a publisher against the shared committed-event stream used by test engines. Call the returned function to unregister it

func (*TestEngineEnv) WaitAfterAll

func (e *TestEngineEnv) WaitAfterAll(count int, fn func([]*wait.Wait))

WaitAfterAll creates multiple consumers, runs fn, and waits with each

func (*TestEngineEnv) WaitFor

func (e *TestEngineEnv) WaitFor(filter wait.EventFilter, fn func())

WaitFor runs fn and waits for a matching event

func (*TestEngineEnv) WaitForCount

func (e *TestEngineEnv) WaitForCount(
	count int, filter wait.EventFilter, fn func(),
)

WaitForCount runs fn and waits for count events

func (*TestEngineEnv) WaitForFlowStatus

func (e *TestEngineEnv) WaitForFlowStatus(
	fid api.FlowID, fn func(),
) api.FlowState

func (*TestEngineEnv) WaitForStepStarted

func (e *TestEngineEnv) WaitForStepStarted(
	fs api.FlowStep, fn func(),
) api.ExecutionState

WaitForStepStarted waits for a step to start and returns the execution

func (*TestEngineEnv) WaitForStepStatus

func (e *TestEngineEnv) WaitForStepStatus(
	fid api.FlowID, sid api.StepID, fn func(),
) api.ExecutionState

WaitForStepStatus waits for a step to finish and returns the execution

func (*TestEngineEnv) WaitForTerminalFlow

func (e *TestEngineEnv) WaitForTerminalFlow(fid api.FlowID) api.FlowState

func (*TestEngineEnv) WaitForTerminalFlows

func (e *TestEngineEnv) WaitForTerminalFlows(
	flowIDs []api.FlowID, timeout time.Duration,
) map[api.FlowID]api.FlowState

WaitForTerminalFlows waits for all flows to reach terminal states

func (*TestEngineEnv) WithConsumer

func (e *TestEngineEnv) WithConsumer(fn func(*event.Consumer))

WithConsumer provides a scoped event consumer for tests

Jump to

Keyboard shortcuts

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