Documentation
¶
Index ¶
- type Comparable
- type ConstructorTest
- type ConstructorTestOption
- type NonTransition
- type TransitionTest
- func Signal(event string, opts ...TransitionTestOption) *TransitionTest[any]
- func Transition[EventData comparable](event string, data EventData, opts ...TransitionTestOption) *TransitionTest[EventData]
- func TransitionWithComparer[EventData any](event string, data EventData, compare func(EventData, EventData) bool, ...) *TransitionTest[EventData]
- func TransitionWithEqual[EventData Comparable[EventData]](event string, data EventData, opts ...TransitionTestOption) *TransitionTest[EventData]
- type TransitionTestOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comparable ¶ added in v0.4.3
Comparable is an interface that provides a method for comparing two instances of the same type. The Equal method should return true if the two instances are considered equivalent, and false otherwise.
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 any] 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 TransitionWithComparer ¶ added in v0.4.5
func TransitionWithComparer[EventData any](event string, data EventData, compare func(EventData, EventData) bool, opts ...TransitionTestOption) *TransitionTest[EventData]
TransitionWithComparer creates a new TransitionTest with the specified event name and data, using a custom comparison function to compare event data. It is used for testing if an aggregate transitions to the specified event with the provided data when running the Run method on a *testing.T instance. TransitionTestOptions can be provided to customize the behavior of the TransitionTest.
func TransitionWithEqual ¶ added in v0.4.3
func TransitionWithEqual[EventData Comparable[EventData]](event string, data EventData, opts ...TransitionTestOption) *TransitionTest[EventData]
TransitionWithEqual creates a new TransitionTest with the specified event name and data, using the Equal method of the Comparable interface to compare event data. It is used for testing if an aggregate transitions to the specified event with the provided data, when running the Run method on a *testing.T instance. The comparison of event data is based on the Equal method, which should be implemented by the provided EventData type. TransitionTestOptions can be provided to customize the behavior of the TransitionTest.
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.