eventtest

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeBus

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

FakeBus is a synchronous in-memory event bus test double that exercises the same Subscribe → Publish flow as the production Bus but skips routing, async fan-in, and middleware composition; suitable for unit tests of resolvers, caches, and other handlers that subscribe to events.

Subscribe registers a handler indexed by event type; Publish invokes all matching handlers in registration order and returns the first non-nil error. PublishOption and SubscribeOption are accepted for signature compatibility but otherwise ignored — in particular, FakeBus does NOT enforce ErrGroupRequired semantics. Tests that need to assert at-least-once group requirements should use an integration test against the real Bus.

FakeBus also records every published event for later inspection via Captured / CapturedByType so tests that previously queried an outbox table can verify behavior without database round-trips.

func NewFakeBus

func NewFakeBus() *FakeBus

NewFakeBus returns a fresh FakeBus with no subscriptions.

func (*FakeBus) Captured

func (b *FakeBus) Captured() []event.Event

Captured returns a snapshot of all events seen by the bus, in publication order.

func (*FakeBus) CapturedByType

func (b *FakeBus) CapturedByType(eventType string) []event.Event

CapturedByType returns the subset of captured events whose EventType() matches the supplied topic.

func (*FakeBus) Publish

func (b *FakeBus) Publish(ctx context.Context, evt event.Event, _ ...event.PublishOption) error

Publish implements event.Bus by synchronously invoking all subscribers for the event type. The event is recorded into the internal capture log before dispatch.

func (*FakeBus) PublishBatch

func (b *FakeBus) PublishBatch(ctx context.Context, evts []event.Event, opts ...event.PublishOption) error

PublishBatch implements event.Bus by publishing each event in order, stopping on the first error.

func (*FakeBus) Reset

func (b *FakeBus) Reset()

Reset clears the capture log so suites can reuse a single bus across subtests.

func (*FakeBus) Subscribe

func (b *FakeBus) Subscribe(eventType string, h event.Handler, _ ...event.SubscribeOption) (event.Unsubscribe, error)

Subscribe implements event.Bus.

Jump to

Keyboard shortcuts

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