Documentation
¶
Overview ¶
Package testing provides test utilities for compensation workflows.
Index ¶
- func MockCompensationFunc(recorder *CompensationRecorder, stepName string) func(ctx workflow.Context, input interface{}) error
- func MockCompensationFuncWithError(recorder *CompensationRecorder, stepName string, err error) func(ctx workflow.Context, input interface{}) error
- type CompensationRecorder
- func (cr *CompensationRecorder) GetCallCount(stepName string) int
- func (cr *CompensationRecorder) GetCompensated() []string
- func (cr *CompensationRecorder) GetError(stepName string) error
- func (cr *CompensationRecorder) Record(stepName string, err error)
- func (cr *CompensationRecorder) Reset()
- func (cr *CompensationRecorder) VerifyCompensationOrder(expected []string) error
- func (cr *CompensationRecorder) WasCompensated(stepName string) bool
- type CompensationTestScenario
- type FailureInjector
- func (fi *FailureInjector) ConfigureDelay(stepName string, delay time.Duration)
- func (fi *FailureInjector) ConfigureErrorType(stepName string, errorType string)
- func (fi *FailureInjector) ConfigureFailure(stepName string)
- func (fi *FailureInjector) ConfigureFailureWithCount(stepName string, count int)
- func (fi *FailureInjector) GetDelay(stepName string) time.Duration
- func (fi *FailureInjector) GetErrorType(stepName string) string
- func (fi *FailureInjector) GetFailureOrder() []string
- func (fi *FailureInjector) Reset()
- func (fi *FailureInjector) ShouldFail(stepName string) bool
- type InjectedError
- type TestActivity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MockCompensationFunc ¶
func MockCompensationFunc(recorder *CompensationRecorder, stepName string) func(ctx workflow.Context, input interface{}) error
MockCompensationFunc creates a mock compensation function that records calls.
func MockCompensationFuncWithError ¶
func MockCompensationFuncWithError(recorder *CompensationRecorder, stepName string, err error) func(ctx workflow.Context, input interface{}) error
MockCompensationFuncWithError creates a mock that records and returns an error.
Types ¶
type CompensationRecorder ¶
type CompensationRecorder struct {
// contains filtered or unexported fields
}
CompensationRecorder records compensation execution for verification.
func NewCompensationRecorder ¶
func NewCompensationRecorder() *CompensationRecorder
NewCompensationRecorder creates a new CompensationRecorder.
func (*CompensationRecorder) GetCallCount ¶
func (cr *CompensationRecorder) GetCallCount(stepName string) int
GetCallCount returns how many times a step was compensated.
func (*CompensationRecorder) GetCompensated ¶
func (cr *CompensationRecorder) GetCompensated() []string
GetCompensated returns the list of compensated steps in order.
func (*CompensationRecorder) GetError ¶
func (cr *CompensationRecorder) GetError(stepName string) error
GetError returns the error for a compensated step.
func (*CompensationRecorder) Record ¶
func (cr *CompensationRecorder) Record(stepName string, err error)
Record records a compensation execution.
func (*CompensationRecorder) Reset ¶
func (cr *CompensationRecorder) Reset()
Reset clears all recorded compensations.
func (*CompensationRecorder) VerifyCompensationOrder ¶
func (cr *CompensationRecorder) VerifyCompensationOrder(expected []string) error
VerifyCompensationOrder verifies compensations occurred in expected order.
func (*CompensationRecorder) WasCompensated ¶
func (cr *CompensationRecorder) WasCompensated(stepName string) bool
WasCompensated returns true if the step was compensated.
type CompensationTestScenario ¶
type CompensationTestScenario struct {
Name string
FailAtStep string
ExpectCompensated []string
ExpectNotCompensated []string
ExpectedError string
}
CompensationTestScenario defines a test scenario for compensation.
func DefaultTestScenarios ¶
func DefaultTestScenarios() []CompensationTestScenario
DefaultTestScenarios returns a set of common test scenarios.
type FailureInjector ¶
type FailureInjector struct {
// contains filtered or unexported fields
}
FailureInjector allows controlled injection of failures for testing compensation.
func NewFailureInjector ¶
func NewFailureInjector() *FailureInjector
NewFailureInjector creates a new FailureInjector instance.
func (*FailureInjector) ConfigureDelay ¶
func (fi *FailureInjector) ConfigureDelay(stepName string, delay time.Duration)
ConfigureDelay sets a delay for a step.
func (*FailureInjector) ConfigureErrorType ¶
func (fi *FailureInjector) ConfigureErrorType(stepName string, errorType string)
ConfigureErrorType sets a custom error type for a step.
func (*FailureInjector) ConfigureFailure ¶
func (fi *FailureInjector) ConfigureFailure(stepName string)
ConfigureFailure sets a step to always fail.
func (*FailureInjector) ConfigureFailureWithCount ¶
func (fi *FailureInjector) ConfigureFailureWithCount(stepName string, count int)
ConfigureFailureWithCount sets a step to fail N times then succeed.
func (*FailureInjector) GetDelay ¶
func (fi *FailureInjector) GetDelay(stepName string) time.Duration
GetDelay returns the configured delay for a step.
func (*FailureInjector) GetErrorType ¶
func (fi *FailureInjector) GetErrorType(stepName string) string
GetErrorType returns the configured error type for a step.
func (*FailureInjector) GetFailureOrder ¶
func (fi *FailureInjector) GetFailureOrder() []string
GetFailureOrder returns the order in which failures occurred.
func (*FailureInjector) Reset ¶
func (fi *FailureInjector) Reset()
Reset clears all configured failures.
func (*FailureInjector) ShouldFail ¶
func (fi *FailureInjector) ShouldFail(stepName string) bool
ShouldFail returns true if the step should fail.
type InjectedError ¶
InjectedError represents a test-injected error.
func NewInjectedError ¶
func NewInjectedError(stepName, errorType, message string) *InjectedError
NewInjectedError creates a new injected error.
func (*InjectedError) Error ¶
func (e *InjectedError) Error() string
Error implements the error interface.
type TestActivity ¶
type TestActivity struct {
// contains filtered or unexported fields
}
TestActivity is a mock activity for testing.
func NewTestActivity ¶
func NewTestActivity(injector *FailureInjector, recorder *CompensationRecorder) *TestActivity
NewTestActivity creates a new TestActivity.
func (*TestActivity) Compensate ¶
func (ta *TestActivity) Compensate(ctx context.Context, stepName string) error
Compensate executes compensation with recording.