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 ¶
- type Record
- type Recorder
- func (r *Recorder) All() []Record
- func (r *Recorder) Len() int
- func (r *Recorder) Of[T event.EventArgs]() []T
- func (r *Recorder) Publish(_ context.Context, args event.EventArgs, opts ...event.PublishOption) (uuid.UUID, error)
- func (r *Recorder) RequireLen(t *testing.T, n int)
- func (r *Recorder) RequireNone[T event.EventArgs](t *testing.T)
- func (r *Recorder) RequireOne[T event.EventArgs](t *testing.T) T
- func (r *Recorder) Reset()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Record ¶
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 (*Recorder) Of ¶ added in v0.0.9
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 ¶
RequireLen asserts exactly n events were published.
func (*Recorder) RequireNone ¶ added in v0.0.9
RequireNone asserts no event of type T was published.
func (*Recorder) RequireOne ¶ added in v0.0.9
RequireOne asserts exactly one event of type T was published and returns it.