eventtest

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 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

func Of

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

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

func RequireNone

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

RequireNone asserts no event of type T was published.

func RequireOne

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

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

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) 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) 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