Documentation ¶
Index ¶
Constants ¶
const (
// FooAggregate is the aggregate name for Foo.
FooAggregate = "foo"
)
Variables ¶
This section is empty.
Functions ¶
func NewAggregate ¶
NewAggregate returns a new test aggregate.
Types ¶
type AggregateOption ¶
type AggregateOption func(*testAggregate)
AggregateOption is an option for a test aggregate.
func ApplyEventFunc ¶
func ApplyEventFunc(eventName string, fn func(event.Event)) AggregateOption
ApplyEventFunc returns an aggregateOption that allows users to intercept calls to a.ApplyEvent.
func CommitFunc ¶
func CommitFunc(fn func(flush func())) AggregateOption
CommitFunc returns an aggregateOption that allows users to intercept a.Commit calls. fn accepts a flush() function that can be called to actually flush the changes.
func RecordChangeFunc ¶ added in v0.1.2
func RecordChangeFunc(fn func(changes []event.Event, track func(...event.Event))) AggregateOption
RecordChangeFunc returns an aggregateOption that allows users to intercept calls to a.RecordChange.
type Foo ¶
type Foo struct {
// contains filtered or unexported fields
}
Foo is an example aggregate used for testing.
func (*Foo) ApplyEvent ¶
ApplyEvent applies an event(https://pkg.go.dev/github.com/modernice/goes/event#Event) to the testAggregate. If a function is registered for the event name of the event, that function will be called instead. If a function is registered for the empty event name, that function will be called instead.
func (*Foo) Commit ¶
func (a *Foo) Commit()
Commit commits the changes recorded in the testAggregate. If a commitFunc AggregateOption was provided to NewAggregate or NewFoo, then that function will be called instead of the default commit function. The provided function should accept a flush function that can be called to actually flush the changes.
func (*Foo) RecordChange ¶ added in v0.1.2
RecordChange is a method that allows users to record changes in the state of an aggregate. It takes one or more events as arguments and stores them in the aggregate's uncommitted changes. If a RecordChangeFunc AggregateOption has been set, it will call that function instead of recording the changes directly. The RecordChangeFunc function accepts two arguments: a slice of changes and a track function that can be used to track additional changes.