helpers

package
v0.0.0-...-e63e094 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package helpers provides additional testing helper functions

Index

Constants

This section is empty.

Variables

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

Functions

func Matcher

func Matcher() policy.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, script string, outputs ...api.Name,
) *api.Step

NewScriptStep creates a script-based step with the specified 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, script string, outputs ...api.Name,
) *api.Step

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

func NewTestConfig

func NewTestConfig() *config.Config

NewTestConfig creates a default configuration with debug logging enabled

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, flowID 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, flowID 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 happens 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 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(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

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

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

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

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 MockCompHandler

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

type MockHandler

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

type Publisher

type Publisher func(...*timebox.Event)

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

Jump to

Keyboard shortcuts

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