test

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FooAggregate is the aggregate name for Foo.
	FooAggregate = "foo"
)

Variables

This section is empty.

Functions

func NewAggregate

func NewAggregate(name string, id uuid.UUID, opts ...AggregateOption) aggregate.Aggregate

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 NewFoo

func NewFoo(id uuid.UUID, opts ...AggregateOption) *Foo

NewFoo returns a new Foo.

func (*Foo) ApplyEvent

func (a *Foo) ApplyEvent(evt event.Event)

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

func (a *Foo) RecordChange(changes ...event.Event)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL