Documentation ¶
Index ¶
- Variables
- func Change(t TestingT, a aggregate.Aggregate, eventName string, opts ...ChangeOption)
- func NewAggregate[Aggregate aggregate.Aggregate](t TestingT, newFunc func(uuid.UUID) Aggregate, expectedName string)
- func NoChange(t TestingT, a aggregate.Aggregate, eventName string, opts ...ChangeOption)
- type ChangeOption
- type ExpectedChangeError
- type TestingT
- type UnexpectedChangeError
Constants ¶
This section is empty.
Variables ¶
var ( // ExampleID is a UUID that can be used in tests. ExampleID = uuid.New() )
Functions ¶
func Change ¶
func Change(t TestingT, a aggregate.Aggregate, eventName string, opts ...ChangeOption)
Change tests an aggregate for a change. The Aggregate must have an uncommitted change with the specified event name.
func NewAggregate ¶
func NewAggregate[Aggregate aggregate.Aggregate](t TestingT, newFunc func(uuid.UUID) Aggregate, expectedName string)
NewAggregate tests the New function of an aggregate to check if the returned aggregate provides the correct aggregateName and AggregateID.
Example:
type Foo struct { *aggregate.Base } func NewFoo() *Foo { return &Foo{Base: aggregate.New()} } func TestNewFoo(t *testing.T) { test.NewAggregate(t, NewFoo, "foo") }
Types ¶
type ChangeOption ¶
type ChangeOption func(*changeConfig)
ChangeOption is an option for the `Change` testing helper.
func AtLeast ¶
func AtLeast(times int) ChangeOption
AtLeast returns a ChangeOption that requires an aggregate to have a change at least as many times as provided.
AtLeast has no effect when used in `NoChange`.
func AtMost ¶
func AtMost(times int) ChangeOption
AtMost returns a ChangeOption that requires an aggregate to have a change at most as many times as provided.
AtMost has no effect when used in `NoChange`.
func EventData ¶
func EventData(data any) ChangeOption
EventData returns a ChangeOption that also tests the event data of changes instead of just the event name.
func Exactly ¶
func Exactly(times int) ChangeOption
Exactly returns a ChangeOption that requires an aggregate to have a change exactly as many times as provided.
Exactly has no effect when used in `NoChange`.
type ExpectedChangeError ¶
type ExpectedChangeError struct { // EventName is the name of the tested change. EventName string // Matches is the number of changes that matched. Matches int // contains filtered or unexported fields }
ExpectedChangeError is returned by the `Change` testing helper when the testd aggregate doesn't have the required change.
func (ExpectedChangeError) Error ¶
func (err ExpectedChangeError) Error() string
Error returns a string representation of an ExpectedChangeError. It formats the error message based on the expected and actual number of changes, the expected event name, and whether or not event data was provided.
type UnexpectedChangeError ¶
type UnexpectedChangeError struct { // EventName is the name of the tested change. EventName string }
UnexpectedChangeError is returned by the `NoChange` testing helper when the testd aggregate does have an unwanted change.
func (UnexpectedChangeError) Error ¶
func (err UnexpectedChangeError) Error() string
Error returns a string representation of UnexpectedChangeError.