Documentation
¶
Overview ¶
Package helpers provides additional testing helper functions
Index ¶
- Constants
- Variables
- func Matcher() api.Matcher
- func NewScriptStep(id api.StepID, language, script string, outputs ...api.Name) *api.Step
- func NewSimpleStep(id api.StepID) *api.Step
- func NewStepWithOutputs(id api.StepID, outputs ...api.Name) *api.Step
- func NewStepWithPredicate(id api.StepID, lang, script string, outputs ...api.Name) *api.Step
- func NewTestStep() *api.Step
- func NewTestStepWithArgs(required []api.Name, optional []api.Name) *api.Step
- func WaitForFlowExists(t *testing.T, eng *engine.Engine, fid api.FlowID) api.FlowState
- func WaitForFlowState(t *testing.T, eng *engine.Engine, q FlowStateQuery) api.FlowState
- func WaitForTerminalFlowState(t *testing.T, eng *engine.Engine, fid api.FlowID) api.FlowState
- func WithEngine(t *testing.T, fn func(*engine.Engine))
- func WithEngineDeps(t *testing.T, overrides engine.Dependencies, fn func(*engine.Engine))
- func WithStartedEngine(t *testing.T, fn func(*engine.Engine))
- func WithTestBackend(t *testing.T, b timebox.Backend, fn func(*TestEngineEnv))
- func WithTestEnv(t *testing.T, fn func(*TestEngineEnv))
- func WithTestEnvDeps(t *testing.T, overrides engine.Dependencies, fn func(*TestEngineEnv))
- type FlowEvent
- type FlowStateQuery
- type MockClient
- func (c *MockClient) ClearError(sid api.StepID)
- func (c *MockClient) ClearInvoke(sid api.StepID)
- func (c *MockClient) Compensate(st *api.Step, args api.Args, md api.Metadata) error
- func (c *MockClient) GetInvocations() []api.StepID
- func (c *MockClient) Invoke(st *api.Step, args api.Args, md api.Metadata) (api.Args, error)
- func (c *MockClient) LastMetadata(sid api.StepID) api.Metadata
- func (c *MockClient) SetCompError(sid api.StepID, err error)
- func (c *MockClient) SetCompensate(sid api.StepID, fn MockCompensate)
- func (c *MockClient) SetError(sid api.StepID, err error)
- func (c *MockClient) SetInvoke(sid api.StepID, fn MockInvoke)
- func (c *MockClient) SetResponse(sid api.StepID, outputs api.Args)
- func (c *MockClient) WaitForInvocation(sid api.StepID, timeout time.Duration) bool
- func (c *MockClient) WasInvoked(sid api.StepID) bool
- type MockCompensate
- type MockInvoke
- type TestEngineEnv
- func (e *TestEngineEnv) AppendEvents(id timebox.AggregateID, atSeq int64, evs ...*timebox.Event) error
- func (e *TestEngineEnv) ConflictFired() bool
- func (e *TestEngineEnv) ConflictOnNextAppend(fid api.FlowID)
- func (e *TestEngineEnv) Dependencies() engine.Dependencies
- func (e *TestEngineEnv) ListFlowsByTag(tag string) ([]timebox.AggregateID, error)
- func (e *TestEngineEnv) NewEngineInstance() (*engine.Engine, error)
- func (e *TestEngineEnv) NewEngineWithConfig(cfg *config.Config, deps engine.Dependencies) (*engine.Engine, func(), error)
- func (e *TestEngineEnv) OpenBackend(pub timebox.Publisher) (timebox.Backend, error)
- func (e *TestEngineEnv) RaiseFlowEvents(fid api.FlowID, evs ...FlowEvent) error
- func (e *TestEngineEnv) ScheduleVersions() (map[timebox.ScheduleKey]timebox.ScheduleVersion, error)
- func (e *TestEngineEnv) SeedFlow(fid api.FlowID, status api.FlowStatus, tags api.Tags) error
- func (e *TestEngineEnv) SeedStartedWork(fs api.FlowStep, pl *api.ExecutionPlan, tkn api.Token) error
- func (e *TestEngineEnv) SubscribeCommitted(fn timebox.Publisher) func()
- func (e *TestEngineEnv) WaitAfterAll(count int, fn func([]*wait.Wait))
- func (e *TestEngineEnv) WaitFor(filter wait.EventFilter, fn func())
- func (e *TestEngineEnv) WaitForCount(count int, filter wait.EventFilter, fn func())
- func (e *TestEngineEnv) WaitForFlowStatus(fid api.FlowID, fn func()) api.FlowState
- func (e *TestEngineEnv) WaitForStepStarted(fs api.FlowStep, fn func()) api.ExecutionState
- func (e *TestEngineEnv) WaitForStepStatus(fid api.FlowID, sid api.StepID, fn func()) api.ExecutionState
- func (e *TestEngineEnv) WaitForTerminalFlow(fid api.FlowID) api.FlowState
- func (e *TestEngineEnv) WaitForTerminalFlows(flowIDs []api.FlowID, timeout time.Duration) map[api.FlowID]api.FlowState
- func (e *TestEngineEnv) WithConsumer(fn func(*event.Consumer))
Constants ¶
const CallbackBaseURL = "http://localhost:8080"
CallbackBaseURL is the base of the webhook URLs test engines hand to async HTTP steps
Variables ¶
var ErrInvalidSeedFlowStatus = errors.New("invalid seeded flow status")
Functions ¶
func 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 ¶
NewScriptStep creates a script-based step with the specified language, code, and output attributes
func NewSimpleStep ¶
NewSimpleStep creates a minimal HTTP step with the specified ID
func NewStepWithOutputs ¶
NewStepWithOutputs creates an HTTP step that produces the specified output attributes
func NewStepWithPredicate ¶
NewStepWithPredicate creates an HTTP step with a predicate script that determines whether the step should execute
func NewTestStep ¶
NewTestStep creates a basic HTTP step for testing with required, optional, and output attributes
func NewTestStepWithArgs ¶
NewTestStepWithArgs creates an HTTP step with the specified required and optional input arguments
func WaitForFlowExists ¶
WaitForFlowExists waits for a flow state to become readable
func WaitForFlowState ¶
WaitForFlowState waits for a flow state accepted by query.Accept
func WaitForTerminalFlowState ¶
WaitForTerminalFlowState waits for a flow to reach a terminal state
func WithEngine ¶
WithEngine creates a test engine, executes the provided function with it, and ensures cleanup happens automatically
func WithEngineDeps ¶
WithEngineDeps creates a test engine with dependency overrides and ensures cleanup happens automatically
func WithStartedEngine ¶
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 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 ¶
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 ¶
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 ¶
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 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) ListFlowsByTag ¶
func (e *TestEngineEnv) ListFlowsByTag( tag string, ) ([]timebox.AggregateID, error)
ListFlowsByTag returns the flow aggregate IDs currently indexed for the tag
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 ¶
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) ScheduleVersions ¶
func (e *TestEngineEnv) ScheduleVersions() ( map[timebox.ScheduleKey]timebox.ScheduleVersion, error, )
ScheduleVersions loads active schedule versions from their aggregate streams
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