test

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package test contains some type implementations of core interfaces that are meant to be used in test code only, not in production code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemoryEventStore

type InMemoryEventStore struct {
	// contains filtered or unexported fields
}

InMemoryEventStore is an in-memory event.Store implementation.

func NewInMemoryEventStore

func NewInMemoryEventStore() *InMemoryEventStore

NewInMemoryEventStore creates a new empty test.InMemoryEventStore instance.

func (*InMemoryEventStore) Append

func (es *InMemoryEventStore) Append(
	_ context.Context,
	id event.StreamID,
	expected version.Check,
	events ...event.Envelope,
) (version.Version, error)

Append inserts the specified Domain Events into the Event Stream specified by the current instance, returning the new version of the Event Stream.

`version.CheckExact` can be specified to enable an Optimistic Concurrency check on append, by using the expected version of the Event Stream prior to appending the new Events.

Alternatively, `version.Any` can be used if no Optimistic Concurrency check should be carried out.

An instance of `version.ConflictError` will be returned if the optimistic locking version check fails against the current version of the Event Stream.

func (*InMemoryEventStore) Stream

func (es *InMemoryEventStore) Stream(
	ctx context.Context,
	eventStream event.StreamWrite,
	id event.StreamID,
	selector version.Selector,
) error

Stream streams committed events in the Event Store onto the provided EventStream, from the specified Global Sequence Number in `from`, based on the provided stream.Target.

Note: this call is synchronous, and will return when all the Events have been successfully written to the provided EventStream, or when the context has been canceled.

This method fails only when the context is canceled.

type TrackingEventStore

type TrackingEventStore struct {
	event.Appender
	// contains filtered or unexported fields
}

TrackingEventStore is an Event Store wrapper to track the Events committed to the inner Event Store.

Useful for tests assertion.

func NewTrackingEventStore

func NewTrackingEventStore(appender event.Appender) *TrackingEventStore

NewTrackingEventStore wraps an Event Store to capture events that get appended to it.

func (*TrackingEventStore) Append

func (es *TrackingEventStore) Append(
	ctx context.Context,
	id event.StreamID,
	expected version.Check,
	events ...event.Envelope,
) (version.Version, error)

Append forwards the call to the wrapped Event Store instance and, if the operation concludes successfully, records these events internally.

The recorded events can be accessed by calling Recorded().

func (*TrackingEventStore) Recorded

func (es *TrackingEventStore) Recorded() []event.Persisted

Recorded returns the list of Events that have been appended to the Event Store.

Please note: these events do not record the Sequence Number assigned by the Event Store. Usually you should not need it in test assertions, since the order of Events in the returned slice always follows the global order of the Event Stream (or the Event Store).

Directories

Path Synopsis
Package scenario contains utilites for testing different parts of a system built with eventually, such as Aggregate Roots, Command Handlers, etc.
Package scenario contains utilites for testing different parts of a system built with eventually, such as Aggregate Roots, Command Handlers, etc.

Jump to

Keyboard shortcuts

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