Documentation
¶
Index ¶
- type FakeBus
- func (b *FakeBus) Captured() []event.Event
- func (b *FakeBus) CapturedByType(eventType string) []event.Event
- func (b *FakeBus) Publish(ctx context.Context, evt event.Event, _ ...event.PublishOption) error
- func (b *FakeBus) PublishBatch(ctx context.Context, evts []event.Event, opts ...event.PublishOption) error
- func (b *FakeBus) Reset()
- func (b *FakeBus) Subscribe(eventType string, h event.Handler, _ ...event.SubscribeOption) (event.Unsubscribe, error)
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 ¶
Captured returns a snapshot of all events seen by the bus, in publication order.
func (*FakeBus) CapturedByType ¶
CapturedByType returns the subset of captured events whose EventType() matches the supplied topic.
func (*FakeBus) Publish ¶
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.