eventtest

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package eventtest provides an in-memory publisher seam for tests: a Recorder that satisfies the same Publish signature as the real event.Publisher, so application code under test can publish without a running runtime and the test can assert on what was published. It is safe for concurrent use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Record

type Record struct {
	ID       uuid.UUID
	Args     event.EventArgs
	OptCount int
}

Record is one captured Publish call: the assigned event id, the event args, and how many publish options were passed.

type Recorder

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

Recorder captures Publish calls in memory.

func New

func New(t *testing.T) *Recorder

New returns an empty Recorder.

func (*Recorder) All

func (r *Recorder) All() []Record

All returns a copy of every captured record, in publish order.

func (*Recorder) Len

func (r *Recorder) Len() int

Len returns how many events were published.

func (*Recorder) Of added in v0.0.9

func (r *Recorder) Of[T event.EventArgs]() []T

Of returns every captured event whose args are of type T, in publish order.

func (*Recorder) Publish

func (r *Recorder) Publish(_ context.Context, args event.EventArgs, opts ...event.PublishOption) (uuid.UUID, error)

Publish records the call and returns a fresh event id, matching the real event.Publisher.Publish signature so it drops in as a seam.

func (*Recorder) RequireLen

func (r *Recorder) RequireLen(t *testing.T, n int)

RequireLen asserts exactly n events were published.

func (*Recorder) RequireNone added in v0.0.9

func (r *Recorder) RequireNone[T event.EventArgs](t *testing.T)

RequireNone asserts no event of type T was published.

func (*Recorder) RequireOne added in v0.0.9

func (r *Recorder) RequireOne[T event.EventArgs](t *testing.T) T

RequireOne asserts exactly one event of type T was published and returns it.

func (*Recorder) Reset

func (r *Recorder) Reset()

Reset discards all captured records.

Jump to

Keyboard shortcuts

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