mocks

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AggregateType is the type for Aggregate.
	AggregateType eh.AggregateType = "Aggregate"

	// EventType is a the type for Event.
	EventType eh.EventType = "Event"
	// EventOtherType is the type for EventOther.
	EventOtherType eh.EventType = "EventOther"

	// CommandType is the type for Command.
	CommandType eh.CommandType = "Command"
	// CommandOtherType is the type for CommandOther.
	CommandOtherType eh.CommandType = "CommandOther"
	// CommandOther2Type is the type for CommandOther2.
	CommandOther2Type eh.CommandType = "CommandOther2"
)

Variables

This section is empty.

Functions

func CompareEvents

func CompareEvents(e1, e2 eh.Event) error

CompareEvents compares two events, ignoring their version and timestamp.

func ContextOne

func ContextOne(ctx context.Context) (string, bool)

ContextOne returns a value for One from the context.

func WithContextOne

func WithContextOne(ctx context.Context, val string) context.Context

WithContextOne sets a value for One one the context.

Types

type Aggregate

type Aggregate struct {
	ID       eh.UUID
	Commands []eh.Command
	Context  context.Context
	// Used to simulate errors in HandleCommand.
	Err error
}

Aggregate is a mocked eventhorizon.Aggregate, useful in testing.

func NewAggregate

func NewAggregate(id eh.UUID) *Aggregate

NewAggregate returns a new Aggregate.

func (*Aggregate) AggregateType

func (a *Aggregate) AggregateType() eh.AggregateType

AggregateType implements the AggregateType method of the eventhorizon.Aggregate interface.

func (*Aggregate) EntityID

func (a *Aggregate) EntityID() eh.UUID

EntityID implements the EntityID method of the eventhorizon.Entity and eventhorizon.Aggregate interface.

func (*Aggregate) HandleCommand

func (a *Aggregate) HandleCommand(ctx context.Context, cmd eh.Command) error

HandleCommand implements the HandleCommand method of the eventhorizon.Aggregate interface.

type AggregateStore

type AggregateStore struct {
	Aggregates map[eh.UUID]eh.Aggregate
	Context    context.Context
	// Used to simulate errors in HandleCommand.
	Err error
}

AggregateStore is a mocked AggregateStore, useful in testing.

func (*AggregateStore) Load

func (m *AggregateStore) Load(ctx context.Context, aggregateType eh.AggregateType, id eh.UUID) (eh.Aggregate, error)

Load implements the Load method of the eventhorizon.AggregateStore interface.

func (*AggregateStore) Save

func (m *AggregateStore) Save(ctx context.Context, aggregate eh.Aggregate) error

Save implements the Save method of the eventhorizon.AggregateStore interface.

type Command

type Command struct {
	ID      eh.UUID
	Content string
}

Command is a mocked eventhorizon.Command, useful in testing.

func (Command) AggregateID

func (t Command) AggregateID() eh.UUID

func (Command) AggregateType

func (t Command) AggregateType() eh.AggregateType

func (Command) CommandType

func (t Command) CommandType() eh.CommandType

type CommandHandler

type CommandHandler struct {
	Commands []eh.Command
	Context  context.Context
	// Used to simulate errors when handling.
	Err error
}

CommandHandler is a mocked eventhorizon.CommandHandler, useful in testing.

func (*CommandHandler) HandleCommand

func (h *CommandHandler) HandleCommand(ctx context.Context, cmd eh.Command) error

HandleCommand implements the HandleCommand method of the eventhorizon.CommandHandler interface.

type CommandOther

type CommandOther struct {
	ID      eh.UUID
	Content string
}

CommandOther is a mocked eventhorizon.Command, useful in testing.

func (CommandOther) AggregateID

func (t CommandOther) AggregateID() eh.UUID

func (CommandOther) AggregateType

func (t CommandOther) AggregateType() eh.AggregateType

func (CommandOther) CommandType

func (t CommandOther) CommandType() eh.CommandType

type CommandOther2

type CommandOther2 struct {
	ID      eh.UUID
	Content string
}

CommandOther2 is a mocked eventhorizon.Command, useful in testing.

func (CommandOther2) AggregateID

func (t CommandOther2) AggregateID() eh.UUID

func (CommandOther2) AggregateType

func (t CommandOther2) AggregateType() eh.AggregateType

func (CommandOther2) CommandType

func (t CommandOther2) CommandType() eh.CommandType

type EmptyAggregate

type EmptyAggregate struct {
}

EmptyAggregate is an empty (non-aggregate).

type EventBus

type EventBus struct {
	Events  []eh.Event
	Context context.Context
	// Used to simulate errors in HandleCommand.
	Err error
}

EventBus is a mocked eventhorizon.EventBus, useful in testing.

func (*EventBus) AddHandler

func (b *EventBus) AddHandler(m eh.EventMatcher, h eh.EventHandler)

AddHandler implements the AddHandler method of the eventhorizon.EventBus interface.

func (*EventBus) PublishEvent

func (b *EventBus) PublishEvent(ctx context.Context, event eh.Event) error

PublishEvent implements the PublishEvent method of the eventhorizon.EventBus interface.

type EventData

type EventData struct {
	Content string
}

EventData is a mocked event data, useful in testing.

type EventHandler

type EventHandler struct {
	Events  []eh.Event
	Context context.Context
	Time    time.Time
	Recv    chan eh.Event
	// Used to simulate errors when publishing.
	Err error
}

EventHandler is a mocked eventhorizon.EventHandler, useful in testing.

func NewEventHandler

func NewEventHandler() *EventHandler

NewEventHandler creates a new EventHandler.

func (*EventHandler) HandleEvent

func (m *EventHandler) HandleEvent(ctx context.Context, event eh.Event) error

HandleEvent implements the HandleEvent method of the eventhorizon.EventHandler interface.

func (*EventHandler) Reset

func (m *EventHandler) Reset()

Reset resets the mock data.

func (*EventHandler) WaitForEvent

func (m *EventHandler) WaitForEvent() error

WaitForEvent is a helper to wait until an event has been handled, it timeouts after 1 second.

type EventObserver

type EventObserver struct {
	Events  []eh.Event
	Context context.Context
	Recv    chan eh.Event
}

EventObserver is a mocked eventhorizon.EventObserver, useful in testing.

func NewEventObserver

func NewEventObserver() *EventObserver

NewEventObserver creates a new EventObserver.

func (*EventObserver) Notify

func (m *EventObserver) Notify(ctx context.Context, event eh.Event)

Notify implements the Notify method of the eventhorizon.EventHandler interface.

func (*EventObserver) WaitForEvent

func (m *EventObserver) WaitForEvent() error

WaitForEvent is a helper to wait until an event has been notified, it timeouts after 1 second.

type EventPublisher

type EventPublisher struct {
	Events    []eh.Event
	Context   context.Context
	Recv      chan eh.Event
	Observers []eh.EventObserver
	// Used to simulate errors when publishing.
	Err error
}

EventPublisher is a mocked eventhorizon.EventPublisher, useful in testing.

func NewEventPublisher

func NewEventPublisher() *EventPublisher

NewEventPublisher creates a new EventPublisher.

func (*EventPublisher) AddObserver

func (m *EventPublisher) AddObserver(o eh.EventObserver)

AddObserver implements the AddObserver method of the eventhorizon.EventPublisher interface.

func (*EventPublisher) HandleEvent

func (m *EventPublisher) HandleEvent(ctx context.Context, event eh.Event) error

HandleEvent implements the HandleEvent method of the eventhorizon.EventPublisher interface.

func (*EventPublisher) WaitForEvent

func (m *EventPublisher) WaitForEvent() error

WaitForEvent is a helper to wait until an event has been notified, it timeouts after 1 second.

type EventStore

type EventStore struct {
	Events  []eh.Event
	Loaded  eh.UUID
	Context context.Context
	// Used to simulate errors in the store.
	Err error
}

EventStore is a mocked eventhorizon.EventStore, useful in testing.

func (*EventStore) Load

func (m *EventStore) Load(ctx context.Context, id eh.UUID) ([]eh.Event, error)

Load implements the Load method of the eventhorizon.EventStore interface.

func (*EventStore) Replace

func (m *EventStore) Replace(ctx context.Context, event eh.Event) error

Replace implements the Replace method of the eventhorizon.EventStore interface.

func (*EventStore) Save

func (m *EventStore) Save(ctx context.Context, events []eh.Event, originalVersion int) error

Save implements the Save method of the eventhorizon.EventStore interface.

type Model

type Model struct {
	ID        eh.UUID   `json:"id"         bson:"_id"`
	Version   int       `json:"version"    bson:"version"`
	Content   string    `json:"content"    bson:"content"`
	CreatedAt time.Time `json:"created_at" bson:"created_at"`
}

Model is a mocked read model, useful in testing.

func (*Model) AggregateVersion

func (m *Model) AggregateVersion() int

AggregateVersion implements the AggregateVersion method of the eventhorizon.Versionable interface.

func (*Model) EntityID

func (m *Model) EntityID() eh.UUID

EntityID implements the EntityID method of the eventhorizon.Entity interface.

type Repo

type Repo struct {
	ParentRepo eh.ReadWriteRepo
	Entity     eh.Entity
	Entities   []eh.Entity
	// Used to simulate errors in the store.
	LoadErr, SaveErr error

	FindCalled, FindAllCalled, SaveCalled, RemoveCalled bool
}

Repo is a mocked eventhorizon.ReadRepo, useful in testing.

func (*Repo) Find

func (r *Repo) Find(ctx context.Context, id eh.UUID) (eh.Entity, error)

Find implements the Find method of the eventhorizon.ReadRepo interface.

func (*Repo) FindAll

func (r *Repo) FindAll(ctx context.Context) ([]eh.Entity, error)

FindAll implements the FindAll method of the eventhorizon.ReadRepo interface.

func (*Repo) Parent

func (r *Repo) Parent() eh.ReadRepo

Parent implements the Parent method of the eventhorizon.ReadRepo interface.

func (*Repo) Remove

func (r *Repo) Remove(ctx context.Context, id eh.UUID) error

Remove implements the Remove method of the eventhorizon.ReadRepo interface.

func (*Repo) Save

func (r *Repo) Save(ctx context.Context, entity eh.Entity) error

Save implements the Save method of the eventhorizon.ReadRepo interface.

type SimpleModel

type SimpleModel struct {
	ID      eh.UUID `json:"id"         bson:"_id"`
	Content string  `json:"content"    bson:"content"`
}

SimpleModel is a mocked read model, useful in testing, without a version.

func (*SimpleModel) EntityID

func (m *SimpleModel) EntityID() eh.UUID

EntityID implements the EntityID method of the eventhorizon.Entity interface.

Jump to

Keyboard shortcuts

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