events

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package events records explicitly selected production event listeners. It never replaces global dispatch or changes transaction/after-commit timing.

Index

Constants

View Source
const MaxEvents = 10000
View Source
const MaxRecordedBytes = 16 << 20

Variables

This section is empty.

Functions

func AssertCount

func AssertCount[E any](t testing.TB, recorder *Recorder[E], want int)

AssertCount reports a test error when the recorded event count differs from want.

func AssertDispatched

func AssertDispatched[E any](t testing.TB, fake *Fake, topic events.Topic[E], match func(E) bool)

AssertDispatched requires at least one dispatch of topic whose payload satisfies match (nil matches any). Failure text never includes payloads.

func AssertDispatchedCount

func AssertDispatchedCount[E any](t testing.TB, fake *Fake, topic events.Topic[E], match func(E) bool, want int)

AssertDispatchedCount requires exactly want dispatches of topic satisfying match.

func AssertNotDispatched

func AssertNotDispatched[E any](t testing.TB, fake *Fake, topic events.Topic[E], match func(E) bool)

AssertNotDispatched requires that no dispatch of topic satisfies match.

func Dispatched

func Dispatched[E any](t testing.TB, fake *Fake, topic events.Topic[E]) []E

Dispatched decodes every recorded payload of topic in dispatch order.

func Start

func Start(t testing.TB, declarations ...events.Declaration) *events.Bus

Start owns a normal production bus with exactly the supplied declarations. To test a complete application use testkit.Start and register the recorder's listener through that application's production events module instead.

Types

type Fake

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

Fake intercepts every dispatch on one production bus for the rest of the test: listeners (sync and queued) do not run, and payload snapshots are recorded for typed assertions. Dispatch still validates and captures the payload exactly as in production. Cleanup restores the bus.

func NewFake

func NewFake(t testing.TB, bus *events.Bus) *Fake

NewFake installs the fake on bus; at most MaxEvents dispatches are recorded.

type Recorder

type Recorder[E any] struct {
	// contains filtered or unexported fields
}

Recorder stores immutable typed payload snapshots in arrival order. The returned listener can coexist with real listeners in the ordinary registry. A dispatch failure does not undo earlier listener observations; use the production Topic.AfterCommit boundary when recording requires committed work.

func New

func New[E any](capacity int) (*Recorder[E], error)

New creates an event recorder with a validated capacity.

func (*Recorder[E]) Count

func (r *Recorder[E]) Count() int

Count returns the synchronized payload count; a nil recorder returns zero.

func (*Recorder[E]) Format

func (*Recorder[E]) Format(state fmt.State, _ rune)

Format writes a fixed label without exposing recorded events.

func (*Recorder[E]) Listener

func (r *Recorder[E]) Listener(id events.ListenerID) events.Listener[E]

Listener returns an event listener that records payloads in this recorder.

func (*Recorder[E]) Payloads

func (r *Recorder[E]) Payloads(ctx context.Context) ([]E, error)

Payloads returns independent decoded values. It never invokes codecs under the recorder lock; a failed decode returns no partial collection.

Jump to

Keyboard shortcuts

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