test

package
v0.0.0-...-eeebc8f Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckConcurrencyValidation

func CheckConcurrencyValidation(t *testing.T, provider StoreProvider)

CheckConcurrencyValidation ensures that basic concurrency safeguards are applied when writing to the aggregate storage, and that we can't get interleaved operations or events.

func CheckDirtyRefresh

func CheckDirtyRefresh(t *testing.T, provider StoreProvider)

CheckDirtyRefresh checks that we can't refresh a dirty aggregate from the store

func CheckStandardSuite

func CheckStandardSuite(t *testing.T, name string, provider StoreProvider)

CheckStandardSuite performs unit testing of all of the various options.

func CheckStartupShutdown

func CheckStartupShutdown(t *testing.T, provider StoreProvider)

CheckStartupShutdown checks a store starts up and shuts down cleanly.

func CheckUnmappedEvent

func CheckUnmappedEvent(t *testing.T, provider StoreProvider)

CheckUnmappedEvent confirms that the event store fails when trying to save an event that does not exist in the mapping registry.

func CheckWritePastEnd

func CheckWritePastEnd(t *testing.T, provider StoreProvider)

CheckWritePastEnd validates you must have an event at N to write at N+1 positions.

func CheckWriteReadNew

func CheckWriteReadNew(t *testing.T, provider StoreProvider)

CheckWriteReadNew validates we can write and then read-lback events

func CheckWriteReadWriteRead

func CheckWriteReadWriteRead(t *testing.T, provider StoreProvider)

CheckWriteReadWriteRead checks that we can perform a looping read/write cycle where we keep appending events to an aggregate.

func CreateErrorStore

func CreateErrorStore(err error) eventsourcing.EventStore

CreateErrorStore creates a store that fails every operation with an error.

func GetTestRegistry

func GetTestRegistry() eventsourcing.EventRegistry

GetTestRegistry returns the test registry for the library.

func MeasureBulkInsertAndReload

func MeasureBulkInsertAndReload(b *testing.B, provider StoreProvider)

MeasureBulkInsertAndReload measures a bulk insert of 1000 events and then reloads the aggregate.

func MeasureIndividualCommits

func MeasureIndividualCommits(b *testing.B, provider StoreProvider)

MeasureIndividualCommits runs a test that measures how fast we can sequentially append to an aggregate.

func NewNullStore

func NewNullStore() eventsourcing.EventStore

NewNullStore creates a null-store, a store that does nothing but accept/discard any data.

Types

type AggregateTest

type AggregateTest struct {
	Commands []AggregateTestCommand `json:"commands"` // Commands to test
	Inherit  string                 `json:"inherit"`  // Previous test to run before this one
	Expect   map[string]interface{} `json:"expect"`   // Post-state of aggregate
}

AggregateTest is a single test for an aggregate, which applies a series of commands to a model and validates outcomes

type AggregateTestCommand

type AggregateTestCommand struct {
	Type  string                 `json:"type"`  // Type of command to create
	Error string                 `json:"error"` // Error/fault to expect, if any
	Data  map[string]interface{} `json:"data"`  // Data for the event
}

AggregateTestCommand is a single command to test against a model

type AggregateTester

type AggregateTester interface {
	// RunRecursive runs al tests from the specified path recursively, looking for files that end in .json
	RunRecursive(t *testing.T, path string) error

	// Run a single test from the specified suite
	Run(t *testing.T, test AggregateTest, suite AggregateTests) error
}

AggregateTester is an interface type for testing aggregates.

func CreateTester

CreateTester initializes an aggregate tester with the specified commands, event store and aggregate factory.

type AggregateTests

type AggregateTests map[string]AggregateTest

AggregateTests is a set of of tests for an aggregate

func LoadTestsFromFile

func LoadTestsFromFile(t *testing.T, fileName string) (AggregateTests, error)

LoadTestsFromFile loads a set of aggregate tests

type CommandFactory

type CommandFactory func(data map[string]interface{}) (eventsourcing.Command, error)

CommandFactory is a method that creates a command from the JSON data

type EventWithInvalidReturnMapping

type EventWithInvalidReturnMapping struct {
	IncrementBy int `json:"increment_by"`
}

EventWithInvalidReturnMapping is an event that does not have a good mapping - it has a reutrn value.

type EventWithTooManyArgumentsMapping

type EventWithTooManyArgumentsMapping struct {
	IncrementBy int `json:"increment_by"`
}

EventWithTooManyArgumentsMapping is an event that does not have a good mapping - it has too many arguments to the replay method.

type IncrementEvent

type IncrementEvent struct {
	IncrementBy int `json:"increment_by"`
}

IncrementEvent represents an event that increments the model value

type InitializeEvent

type InitializeEvent struct {
	// TargetValue is the value the counter will count towards.
	TargetValue int `json:"target_value"`
}

InitializeEvent is an event that initializes the current state of an event.

type LoggingHandler

type LoggingHandler struct {
	Events []eventsourcing.PublishedEvent // Published events
}

LoggingHandler is a handler that tracks events into a collection so we can see what's been sent to the handler

func CreateLoggingHandler

func CreateLoggingHandler() LoggingHandler

CreateLoggingHandler creates a handler that can process events

func (*LoggingHandler) Handle

func (logger *LoggingHandler) Handle(event eventsourcing.PublishedEvent) error

Handle an event

type NullStore

type NullStore struct {
}

The NullStore is a simple store implementation that does nothing besides clear the pending events on commit. Basically it's an event black-hole, and should only be used for stateless tests.

func (*NullStore) Close

func (store *NullStore) Close() error

Close the event store

func (*NullStore) CommitEvents

func (store *NullStore) CommitEvents(adapter eventsourcing.StoreWriterAdapter) error

CommitEvents writes events to a backing store. However, for the NullStore we simply do nothing and discard anything sent in.

func (*NullStore) Refresh

func (store *NullStore) Refresh(adapter eventsourcing.StoreLoaderAdapter) error

Refresh the state of the aggregate from the store. Does nothing and will never change aggregate state.

type ProviderFunc

type ProviderFunc func(store eventsourcing.EventStore) error

ProviderFunc is a test function that runs in the context of a provider

type SimpleAggregate

type SimpleAggregate struct {
	eventsourcing.AggregateBase
	CurrentCount int `json:"current_count"`
	TargetValue  int `json:"target_value"`
}

SimpleAggregate is a simple aggregate that counts up or down.

func (*SimpleAggregate) Initialize

func (agg *SimpleAggregate) Initialize(key string, registry eventsourcing.EventRegistry, store eventsourcing.EventStore)

Initialize the aggregate

func (*SimpleAggregate) ReplayEventWithInvalidReturnMapping

func (agg *SimpleAggregate) ReplayEventWithInvalidReturnMapping(event EventWithInvalidReturnMapping) int

ReplayEventWithInvalidReturnMapping has a return value, and should not be wired up.

func (*SimpleAggregate) ReplayEventWithTooManyArgumentsMapping

func (agg *SimpleAggregate) ReplayEventWithTooManyArgumentsMapping(event EventWithInvalidReturnMapping, extraParameter int)

ReplayEventWithTooManyArgumentsMapping has an extra parameter, and should not trigger an increment event.

func (*SimpleAggregate) ReplayIncrementEvent

func (agg *SimpleAggregate) ReplayIncrementEvent(event IncrementEvent)

ReplayIncrementEvent applies an IncrementEvent to the model.

func (*SimpleAggregate) ReplayInitializeEvent

func (agg *SimpleAggregate) ReplayInitializeEvent(event InitializeEvent)

ReplayInitializeEvent applies an InitializeEvent to the model.

type StoreProvider

type StoreProvider func() (eventsourcing.EventStore, func(), error)

A StoreProvider is a structure

type UnknownEventTypeExample

type UnknownEventTypeExample struct {
}

UnknownEventTypeExample is an event that is just made out of the ether, and is not supported by SimpleAggregate. What should happen here is that the sequence jumps even though it's not wired up.

Jump to

Keyboard shortcuts

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