Documentation
¶
Overview ¶
Package helpers provides additional testing helper functions
Index ¶
- Variables
- func Matcher() policy.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 NewTestConfig() *config.Config
- func NewTestStep() *api.Step
- func NewTestStepWithArgs(required []api.Name, optional []api.Name) *api.Step
- func WaitForFlowExists(t *testing.T, eng *engine.Engine, flowID api.FlowID) api.FlowState
- func WaitForFlowState(t *testing.T, eng *engine.Engine, q FlowStateQuery) api.FlowState
- func WaitForTerminalFlowState(t *testing.T, eng *engine.Engine, flowID 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 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(stepID api.StepID)
- func (c *MockClient) ClearHandler(stepID api.StepID)
- func (c *MockClient) GetInvocations() []api.StepID
- func (c *MockClient) Invoke(step *api.Step, args api.Args, md api.Metadata) (api.Args, error)
- func (c *MockClient) InvokeCompensate(step *api.Step, inputs api.Args, outputs api.Args, md api.Metadata) error
- func (c *MockClient) LastMetadata(stepID api.StepID) api.Metadata
- func (c *MockClient) SetCompError(stepID api.StepID, err error)
- func (c *MockClient) SetCompHandler(stepID api.StepID, handler MockCompHandler)
- func (c *MockClient) SetError(stepID api.StepID, err error)
- func (c *MockClient) SetHandler(stepID api.StepID, handler MockHandler)
- func (c *MockClient) SetResponse(stepID api.StepID, outputs api.Args)
- func (c *MockClient) WaitForInvocation(stepID api.StepID, timeout time.Duration) bool
- func (c *MockClient) WasInvoked(stepID api.StepID) bool
- type MockCompHandler
- type MockHandler
- type Publisher
- type TestEngineEnv
- func (e *TestEngineEnv) AppendEvents(id timebox.AggregateID, atSeq int64, evs ...*timebox.Event) error
- func (e *TestEngineEnv) Dependencies() engine.Dependencies
- func (e *TestEngineEnv) ListFlowsByLabel(label, value 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) RaiseFlowEvents(flowID api.FlowID, evs ...FlowEvent) error
- func (e *TestEngineEnv) SeedFlow(flowID api.FlowID, status api.FlowStatus, labels api.Labels) error
- func (e *TestEngineEnv) SubscribeCommitted(fn 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(flowID api.FlowID, fn func()) api.FlowState
- func (e *TestEngineEnv) WaitForStepStarted(fs api.FlowStep, fn func()) api.ExecutionState
- func (e *TestEngineEnv) WaitForStepStatus(flowID api.FlowID, stepID api.StepID, fn func()) api.ExecutionState
- func (e *TestEngineEnv) WaitForTerminalFlow(flowID 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 ¶
This section is empty.
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 NewTestConfig ¶
NewTestConfig creates a default configuration with debug logging enabled
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 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(stepID api.StepID)
ClearError removes any configured error for a step
func (*MockClient) ClearHandler ¶
func (c *MockClient) ClearHandler(stepID api.StepID)
ClearHandler removes a custom handler for a step
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) InvokeCompensate ¶
func (c *MockClient) InvokeCompensate( step *api.Step, inputs api.Args, outputs api.Args, md api.Metadata, ) error
InvokeCompensate records the compensate invocation and returns any configured error
func (*MockClient) LastMetadata ¶
func (c *MockClient) LastMetadata(stepID api.StepID) api.Metadata
LastMetadata returns the most recent metadata passed for a step invocation
func (*MockClient) SetCompError ¶
func (c *MockClient) SetCompError(stepID api.StepID, err error)
SetCompError configures the mock to return an error on compensation
func (*MockClient) SetCompHandler ¶
func (c *MockClient) SetCompHandler( stepID api.StepID, handler MockCompHandler, )
SetCompHandler configures a custom compensation handler for a step
func (*MockClient) SetError ¶
func (c *MockClient) SetError(stepID api.StepID, err error)
SetError configures the mock to return an error for a step
func (*MockClient) SetHandler ¶
func (c *MockClient) SetHandler(stepID api.StepID, handler MockHandler)
SetHandler configures a custom invocation handler for a step
func (*MockClient) SetResponse ¶
func (c *MockClient) SetResponse(stepID 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(stepID 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) Dependencies ¶
func (e *TestEngineEnv) Dependencies() engine.Dependencies
Dependencies returns a valid dependency bundle for constructing an engine
func (*TestEngineEnv) ListFlowsByLabel ¶
func (e *TestEngineEnv) ListFlowsByLabel( label, value string, ) ([]timebox.AggregateID, error)
ListFlowsByLabel returns the flow aggregate IDs currently indexed for the given label/value pair
func (*TestEngineEnv) NewEngineInstance ¶
func (e *TestEngineEnv) NewEngineInstance() (*engine.Engine, error)
NewEngineInstance creates a new engine instance sharing the same stores 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) RaiseFlowEvents ¶
func (e *TestEngineEnv) RaiseFlowEvents( flowID api.FlowID, evs ...FlowEvent, ) error
RaiseFlowEvents appends flow events via the executor
func (*TestEngineEnv) SeedFlow ¶
func (e *TestEngineEnv) SeedFlow( flowID api.FlowID, status api.FlowStatus, labels api.Labels, ) error
SeedFlow stores a minimal valid flow history for state/query fixtures
func (*TestEngineEnv) SubscribeCommitted ¶
func (e *TestEngineEnv) SubscribeCommitted(fn 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( flowID 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( flowID api.FlowID, stepID api.StepID, fn func(), ) api.ExecutionState
WaitForStepStatus waits for a step to finish and returns the execution
func (*TestEngineEnv) WaitForTerminalFlow ¶
func (e *TestEngineEnv) WaitForTerminalFlow(flowID 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