Documentation
¶
Overview ¶
Package sagas provides testing utilities for saga (process manager) development. It includes fixtures for testing saga state transitions, event handling, and command generation.
Index ¶
- type CompensationFixture
- type Saga
- type SagaCompensator
- type SagaState
- type SagaStateMachineFixture
- type SagaTestFixture
- func (f *SagaTestFixture) Commands() []mink.Command
- func (f *SagaTestFixture) GivenEvents(events ...mink.StoredEvent) *SagaTestFixture
- func (f *SagaTestFixture) Saga() Saga
- func (f *SagaTestFixture) ThenCommandCount(expected int) *SagaTestFixture
- func (f *SagaTestFixture) ThenCommands(expected ...mink.Command) *SagaTestFixture
- func (f *SagaTestFixture) ThenCompleted() *SagaTestFixture
- func (f *SagaTestFixture) ThenContainsCommand(expected mink.Command) *SagaTestFixture
- func (f *SagaTestFixture) ThenError(expected error) *SagaTestFixture
- func (f *SagaTestFixture) ThenFirstCommand(expected mink.Command) *SagaTestFixture
- func (f *SagaTestFixture) ThenLastCommand(expected mink.Command) *SagaTestFixture
- func (f *SagaTestFixture) ThenNoCommands() *SagaTestFixture
- func (f *SagaTestFixture) ThenNotCompleted() *SagaTestFixture
- func (f *SagaTestFixture) ThenState(expected interface{}) *SagaTestFixture
- func (f *SagaTestFixture) WithContext(ctx context.Context) *SagaTestFixture
- type SagaWithTimeout
- type StateTransition
- type TB
- type TimeoutFixture
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompensationFixture ¶
type CompensationFixture struct {
// contains filtered or unexported fields
}
CompensationFixture tests saga compensation (rollback) behavior.
func TestCompensation ¶
func TestCompensation(t TB, saga Saga) *CompensationFixture
TestCompensation creates a new compensation test fixture.
func (*CompensationFixture) GivenFailureAfter ¶
func (f *CompensationFixture) GivenFailureAfter(events ...mink.StoredEvent) *CompensationFixture
GivenFailureAfter simulates a failure after certain events.
func (*CompensationFixture) ThenCompensates ¶
func (f *CompensationFixture) ThenCompensates(expected ...mink.Command)
ThenCompensates asserts the expected compensation commands.
type Saga ¶
type Saga interface {
// Name returns the saga's unique identifier.
Name() string
// HandleEvent processes an event and returns commands to dispatch.
HandleEvent(ctx context.Context, event mink.StoredEvent) ([]mink.Command, error)
// IsComplete returns true if the saga has completed.
IsComplete() bool
// State returns the current saga state.
State() interface{}
}
Saga represents a saga or process manager interface. Sagas coordinate long-running processes by listening to events and dispatching commands.
type SagaCompensator ¶
SagaCompensator is implemented by sagas that support compensation.
type SagaStateMachineFixture ¶
type SagaStateMachineFixture struct {
// contains filtered or unexported fields
}
SagaStateMachineFixture tests saga state machine behavior.
func TestSagaStateMachine ¶
func TestSagaStateMachine(t TB, saga Saga) *SagaStateMachineFixture
TestSagaStateMachine creates a new state machine test fixture.
func (*SagaStateMachineFixture) ExpectTransition ¶
func (f *SagaStateMachineFixture) ExpectTransition(from, to SagaState, event, command string) *SagaStateMachineFixture
ExpectTransition defines an expected state transition.
func (*SagaStateMachineFixture) Transitions ¶
func (f *SagaStateMachineFixture) Transitions() []StateTransition
Transitions returns the expected transitions for verification.
type SagaTestFixture ¶
type SagaTestFixture struct {
// contains filtered or unexported fields
}
SagaTestFixture provides BDD-style testing for sagas.
func TestSaga ¶
func TestSaga(t TB, saga Saga) *SagaTestFixture
TestSaga creates a new saga test fixture.
func (*SagaTestFixture) Commands ¶
func (f *SagaTestFixture) Commands() []mink.Command
Commands returns the collected commands for additional assertions.
func (*SagaTestFixture) GivenEvents ¶
func (f *SagaTestFixture) GivenEvents(events ...mink.StoredEvent) *SagaTestFixture
GivenEvents applies events to the saga and collects commands.
func (*SagaTestFixture) Saga ¶
func (f *SagaTestFixture) Saga() Saga
Saga returns the underlying saga for additional assertions.
func (*SagaTestFixture) ThenCommandCount ¶
func (f *SagaTestFixture) ThenCommandCount(expected int) *SagaTestFixture
ThenCommandCount asserts the number of commands produced.
func (*SagaTestFixture) ThenCommands ¶
func (f *SagaTestFixture) ThenCommands(expected ...mink.Command) *SagaTestFixture
ThenCommands asserts that the saga produced the expected commands.
func (*SagaTestFixture) ThenCompleted ¶
func (f *SagaTestFixture) ThenCompleted() *SagaTestFixture
ThenCompleted asserts that the saga has completed.
func (*SagaTestFixture) ThenContainsCommand ¶
func (f *SagaTestFixture) ThenContainsCommand(expected mink.Command) *SagaTestFixture
ThenContainsCommand asserts that a command exists in the produced commands.
func (*SagaTestFixture) ThenError ¶
func (f *SagaTestFixture) ThenError(expected error) *SagaTestFixture
ThenError asserts that an error occurred during event handling.
func (*SagaTestFixture) ThenFirstCommand ¶
func (f *SagaTestFixture) ThenFirstCommand(expected mink.Command) *SagaTestFixture
ThenFirstCommand asserts the first command matches.
func (*SagaTestFixture) ThenLastCommand ¶
func (f *SagaTestFixture) ThenLastCommand(expected mink.Command) *SagaTestFixture
ThenLastCommand asserts the last command matches.
func (*SagaTestFixture) ThenNoCommands ¶
func (f *SagaTestFixture) ThenNoCommands() *SagaTestFixture
ThenNoCommands asserts that no commands were produced.
func (*SagaTestFixture) ThenNotCompleted ¶
func (f *SagaTestFixture) ThenNotCompleted() *SagaTestFixture
ThenNotCompleted asserts that the saga has not completed.
func (*SagaTestFixture) ThenState ¶
func (f *SagaTestFixture) ThenState(expected interface{}) *SagaTestFixture
ThenState asserts the saga's current state.
func (*SagaTestFixture) WithContext ¶
func (f *SagaTestFixture) WithContext(ctx context.Context) *SagaTestFixture
WithContext sets a custom context for event handling.
type SagaWithTimeout ¶
SagaWithTimeout is implemented by sagas that support timeouts.
type StateTransition ¶
StateTransition represents a state transition in a saga.
type TimeoutFixture ¶
type TimeoutFixture struct {
// contains filtered or unexported fields
}
TimeoutFixture tests saga timeout behavior.
func TestTimeout ¶
func TestTimeout(t TB, saga Saga) *TimeoutFixture
TestTimeout creates a new timeout test fixture.
func (*TimeoutFixture) ThenOnTimeout ¶
func (f *TimeoutFixture) ThenOnTimeout(expected ...mink.Command)
ThenOnTimeout simulates a timeout and checks commands.
func (*TimeoutFixture) WithContext ¶
func (f *TimeoutFixture) WithContext(ctx context.Context) *TimeoutFixture
WithContext sets a custom context (can include timeout).