test

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
}

func NoChange

func NoChange(t TestingT, a aggregate.Aggregate, eventName string, opts ...ChangeOption)

Change tests an aggregate for a change. The Aggregate must not have an uncommitted change with the specified event name.

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

type TestingT

type TestingT interface {
	Fatal(...any)
}

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

Directories

Path Synopsis
Package mock_test is a generated GoMock package.
Package mock_test is a generated GoMock package.

Jump to

Keyboard shortcuts

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