Documentation
¶
Overview ¶
Package scenario exposes declarative testing support for multiple components pertaining the Eventually library, such as Command Handlers, Projections, etc.
Index ¶
- type CommandHandlerGiven
- type CommandHandlerInit
- type CommandHandlerThen
- type CommandHandlerWhen
- type ProcessManagerFactory
- type ProcessManagerGiven
- type ProcessManagerInit
- type ProcessManagerThen
- type ProcessManagerWhen
- type ProjectionGiven
- type ProjectionInit
- type ProjectionThen
- type ProjectionWhen
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandHandlerGiven ¶
type CommandHandlerGiven struct {
// contains filtered or unexported fields
}
CommandHandlerGiven is the state of the scenario once a set of Domain Events have been provided using Given(), to represent the state of the system at the time of evaluating a Command.
func (CommandHandlerGiven) When ¶
func (sc CommandHandlerGiven) When(cmd eventually.Command) CommandHandlerWhen
When provides the Command to evaluate.
type CommandHandlerInit ¶
type CommandHandlerInit struct{}
CommandHandlerInit is the entrypoint of the Command Handler scenario API.
A Command Handler scenario can either set the current evaluation context by using Given(), or test a "clean-slate" scenario by using When() directly.
func CommandHandler ¶
func CommandHandler() CommandHandlerInit
CommandHandler is a scenario type to test the result of Commands being handled by a Command Handler.
Command Handlers in Event-sourced systems produce side effects by means of Domain Events. This scenario API helps you with testing the Domain Events produced by a Command Handler when handling a specific Command.
func (CommandHandlerInit) Given ¶
func (sc CommandHandlerInit) Given(events ...eventstore.Event) CommandHandlerGiven
Given sets the Command Handler scenario preconditions.
Domain Events are used in Event-sourced systems to represent a side effect that has taken place in the system. In order to set a given state for the system to be in while testing a specific Command evaluation, you should specify the Domain Events that have happened thus far.
When you're testing Commands with a clean-slate system, you should either specify no Domain Events, or skip directly to When().
func (CommandHandlerInit) When ¶
func (sc CommandHandlerInit) When(cmd eventually.Command) CommandHandlerWhen
When provides the Command to evaluate.
type CommandHandlerThen ¶
type CommandHandlerThen struct {
CommandHandlerWhen
// contains filtered or unexported fields
}
CommandHandlerThen is the state of the scenario once the preconditions and expectations have been fully specified.
func (CommandHandlerThen) Using ¶
func (sc CommandHandlerThen) Using( t *testing.T, aggregateType aggregate.Type, handlerFactory func(*aggregate.Repository) command.Handler, )
Using performs the specified expectations of the scenario, using the Command Handler instance produced by the provided factory function.
A Command Handler should only use a single Aggregate type, to ensure that the side effects happen in a well-defined transactional boundary. If your Command Handler needs to modify more than one Aggregate, you might be doing something wrong in your domain model.
The type of the Aggregate used to evaluate the Command must be specified, so that the Event-sourced Repository instance can be provided to the factory function to build the desired Command Handler.
type CommandHandlerWhen ¶
type CommandHandlerWhen struct {
CommandHandlerGiven
// contains filtered or unexported fields
}
CommandHandlerWhen is the state of the scenario once the state of the system and the Command to evaluate have been provided.
func (CommandHandlerWhen) Then ¶
func (sc CommandHandlerWhen) Then(events ...eventstore.Event) CommandHandlerThen
Then sets a positive expectation on the scenario outcome, to produce the Domain Events provided in input.
The list of Domain Events specified should be ordered as the expected order of recording by the Command Handler.
func (CommandHandlerWhen) ThenError ¶
func (sc CommandHandlerWhen) ThenError(err error) CommandHandlerThen
ThenError sets a negative expectation on the scenario outcome, to produce an error value that is similar to the one provided in input.
Error assertion happens using errors.Is(), so the error returned by the Command Handler is unwrapped until the cause error to match the provided expectation.
func (CommandHandlerWhen) ThenFails ¶
func (sc CommandHandlerWhen) ThenFails() CommandHandlerThen
ThenFails sets a negative expectation on the scenario outcome, to fail the Command execution with no particular assertion on the error returned.
This is useful when the error returned is not important for the Command you're trying to test.
type ProcessManagerFactory ¶
type ProcessManagerFactory func(cd command.Dispatcher) projection.Applier
ProcessManagerFactory is the factory function used by the Process Manager scenario to build the Process Manager type to test.
type ProcessManagerGiven ¶
type ProcessManagerGiven struct {
// contains filtered or unexported fields
}
ProcessManagerGiven is the state of the scenario once a set of Domain Events have been provided using Given() to represent the state of the Process Manager at the time of processing a new Domain Event.
func (ProcessManagerGiven) When ¶
func (sc ProcessManagerGiven) When(event eventstore.Event) *ProcessManagerWhen
When provides the persisted Domain Event the Process Manager should process.
type ProcessManagerInit ¶
type ProcessManagerInit struct{}
ProcessManagerInit is the entrypoint of the Process Manager scenario API.
func ProcessManager ¶
func ProcessManager() ProcessManagerInit
ProcessManager is a scenario type to test the Domain Commands issued by a Process Manager when handling a certain persisted Domain Event.
Process Managers in Event-sourced systems react to incoming Domain Events, persisted in the Event Store, and optionally produce "compensating actions" in the form of Domain Commands, in order to implement certain business processes (hence the name "Process Manager").
func (ProcessManagerInit) Given ¶
func (ProcessManagerInit) Given(events ...eventstore.Event) ProcessManagerGiven
Given sets the Process Manager state before the assertion.
The specified Domain Events will be applied on the Process Manager before the Domain Event to test (later specified with When()). Depending on the Process Manager implementation, applying these Events could either have no meaningful value, or update some internal state or Read Model maintained by the Process Manager.
type ProcessManagerThen ¶
type ProcessManagerThen struct {
*ProcessManagerWhen
// contains filtered or unexported fields
}
ProcessManagerThen is the state of the scenario once the preconditions and expectations have been fully specified.
func (ProcessManagerThen) Using ¶
func (sc ProcessManagerThen) Using(t *testing.T, processManagerFactory ProcessManagerFactory)
Using performs the specified expectations of the scenario, using the Process Manager instance produced by the provided factory function.
type ProcessManagerWhen ¶
type ProcessManagerWhen struct {
ProcessManagerGiven
// contains filtered or unexported fields
}
ProcessManagerWhen is the state of the scenario once the state of the Process Manager and the Domain Event to process have been set.
This type is used with pointer semantics to save some space in memory.
func (*ProcessManagerWhen) Then ¶
func (sc *ProcessManagerWhen) Then(commands ...eventually.Command) ProcessManagerThen
Then sets a positive expectation on the scenario outcome, which should be a list of Commands issued as a result of the Domain Event processed.
func (*ProcessManagerWhen) ThenError ¶
func (sc *ProcessManagerWhen) ThenError(err error) ProcessManagerThen
ThenError sets a negative expectation on the scenario outcome, to produce an error value that is similar to the one provided in input.
Error assertion happens using errors.Is(), so the error returned by the Projection is unwrapped until the cause error to match the provided expectation.
func (*ProcessManagerWhen) ThenFails ¶
func (sc *ProcessManagerWhen) ThenFails() ProcessManagerThen
ThenFails sets a negative expectation on the scenario outcome, to fail the processing of the Domain Event with no particular assertion on the error returned.
This is useful when the error returned is not important for the Domain Event you're trying to test.
type ProjectionGiven ¶
type ProjectionGiven struct {
// contains filtered or unexported fields
}
ProjectionGiven is the state of the scenario once a set of Domain Events have been provided using Given(), to represent the state of the Read Model/Projection at the time of evaluating a Domain Query.
func (ProjectionGiven) When ¶
func (s ProjectionGiven) When(q query.Query) ProjectionWhen
When provides the Domain Query to evaluate using the Read Model/Projection.
type ProjectionInit ¶
type ProjectionInit struct{}
ProjectionInit is the entrypoint of the Projection scenario API.
func Projection ¶
func Projection() ProjectionInit
Projection is a scenario type to test the result of a Domain Query being handled by a Projection, or Domain Read Model.
Projections in Event-sourced systems are updated by means of Domain Events, and sometimes used specifically for building optimized Read Models to satisfy rather specific Domain Queries.
func (ProjectionInit) Given ¶
func (s ProjectionInit) Given(events ...eventstore.Event) ProjectionGiven
Given sets the Projection state before the assertion.
Domain Events are used in Event-sourced systems to represent a side effect that has taken place in the system. Thus, they're also used by Projections as a trigger to perform an update on their internal state.
type ProjectionThen ¶
type ProjectionThen struct {
ProjectionWhen
// contains filtered or unexported fields
}
ProjectionThen is the state of the scenario once the preconditions and expectations have been fully specified.
func (ProjectionThen) Using ¶
func (s ProjectionThen) Using(t *testing.T, projectionFactory func() projection.Projection)
Using performs the specified expectations of the scenario, using the Projection instance produced by the provided factory function.
type ProjectionWhen ¶
type ProjectionWhen struct {
ProjectionGiven
// contains filtered or unexported fields
}
ProjectionWhen is the state of the scenario once the state of the Read Model/Projection and the Domain Query to evaluate have been provided.
func (ProjectionWhen) Then ¶
func (s ProjectionWhen) Then(answer query.Answer) ProjectionThen
Then sets a positive expectation on the scenario outcome, to produce the Answer provided in input.
func (ProjectionWhen) ThenError ¶
func (s ProjectionWhen) ThenError(err error) ProjectionThen
ThenError sets a negative expectation on the scenario outcome, to produce an error value that is similar to the one provided in input.
Error assertion happens using errors.Is(), so the error returned by the Projection is unwrapped until the cause error to match the provided expectation.
func (ProjectionWhen) ThenFails ¶
func (s ProjectionWhen) ThenFails() ProjectionThen
ThenFails sets a negative expectation on the scenario outcome, to fail the Query execution with no particular assertion on the error returned.
This is useful when the error returned is not important for the Domain Query you're trying to test.