Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConstructorTest ¶
type ConstructorTest[A aggregate.Aggregate] struct { Constructor func(uuid.UUID) A OnCreated func(A) error }
ConstructorTest is a test for aggregate constructors. It checks if the constructor properly sets the AggregateID and calls the OnCreated hook, if provided, with the created aggregate.
func Constructor ¶
func Constructor[A aggregate.Aggregate](constructor func(uuid.UUID) A, opts ...ConstructorTestOption[A]) *ConstructorTest[A]
Constructor creates a new ConstructorTest with the specified constructor function and optional test options. It returns a pointer to the created ConstructorTest.
func (*ConstructorTest[A]) Run ¶
func (test *ConstructorTest[A]) Run(t *testing.T)
Run executes the ConstructorTest, ensuring that the constructed aggregate has the correct UUID and, if provided, calls the OnCreated hook without errors. If any of these checks fail, an error is reported to the given testing.T.
type ConstructorTestOption ¶
type ConstructorTestOption[A aggregate.Aggregate] func(*ConstructorTest[A])
ConstructorTestOption is a function that modifies a ConstructorTest for an Aggregate. It is used to customize the behavior of a ConstructorTest, such as providing a custom OnCreated hook function.
func Created ¶
func Created[A aggregate.Aggregate](fn func(A) error) ConstructorTestOption[A]
Created configures a ConstructorTest with a custom function to be called when an Aggregate is created, allowing for additional validation or setup steps. The provided function takes the created Aggregate as its argument and returns an error if any issues are encountered during execution.
type NonTransition ¶
type NonTransition string
NonTransition represents an event that the aggregate should not transition to. It's used in testing to ensure that a specific event does not occur during the test run for a given aggregate.
type TransitionTest ¶
type TransitionTest[EventData comparable] struct { Event string Data EventData // contains filtered or unexported fields }
TransitionTest represents a test that checks whether an aggregate transitions to a specific event with the specified data. It can be used to ensure that an aggregate properly handles its internal state changes and produces the correct events with the expected data.
func Signal ¶
func Signal(event string, opts ...TransitionTestOption) *TransitionTest[any]
Signal returns a new TransitionTest with the specified event name and no event data. It is used to test aggregate transitions for events without data.
func Transition ¶
func Transition[EventData comparable](event string, data EventData, opts ...TransitionTestOption) *TransitionTest[EventData]
Transition creates a new TransitionTest with the specified event name and data. It can be used to test if an aggregate transitions to the specified event with the provided data when running the Run method on a *testing.T instance.
func (*TransitionTest[EventData]) Run ¶
func (test *TransitionTest[EventData]) Run(t *testing.T, a aggregate.Aggregate)
Run tests whether an aggregate transitions to the specified event with the expected data. It reports an error if the aggregate does not transition to the specified event, or if the event data does not match the expected data.
type TransitionTestOption ¶
type TransitionTestOption func(*transitionTestConfig)
TransitionTestOption is a function that modifies the behavior of a TransitionTest, such as configuring the number of times an event should be matched. It takes a transitionTestConfig struct and modifies its properties based on the desired configuration.
func Once ¶
func Once() TransitionTestOption
Once returns a TransitionTestOption that configures a TransitionTest to expect the specified event and data exactly once.
func Times ¶
func Times(times uint) TransitionTestOption
Times is a TransitionTestOption that configures the number of times an event should match the expected data in a TransitionTest. It takes an unsigned integer argument representing the number of matches expected.