testing

package
v0.64.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package testing provides test doubles for the messaging package's module-facing surface. It is the publish-side complement of testing/mocks: since ADR-096 no exported client carries a byte publish method, a module's publishes are observed at the typed handle, not at the client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CapturePublisher

type CapturePublisher[T any] struct {
	// contains filtered or unexported fields
}

CapturePublisher is a messaging.EventPublisher[T] that records every event it is asked to publish and returns the configured error. A module stores its *messaging.Publisher[T] behind messaging.EventPublisher[T] and a test injects this in its place — the typed value is what gets asserted, never a frame of bytes the test would have to re-decode.

Safe for concurrent use: handlers publish from many goroutines.

func NewCapturePublisher

func NewCapturePublisher[T any]() *CapturePublisher[T]

NewCapturePublisher returns an empty capture whose Publish succeeds.

func (*CapturePublisher[T]) Events

func (c *CapturePublisher[T]) Events() []T

Events returns every recorded event, oldest first, as a copy the caller owns.

func (*CapturePublisher[T]) Fail

func (c *CapturePublisher[T]) Fail(err error)

Fail makes every later Publish return err (nil restores success). The event is still recorded, so a test can assert what the module attempted.

func (*CapturePublisher[T]) Last

func (c *CapturePublisher[T]) Last() (evt T, ok bool)

Last returns the most recent event and whether there was one.

func (*CapturePublisher[T]) Publish

func (c *CapturePublisher[T]) Publish(_ context.Context, _ messaging.AMQPClient, evt T) error

Publish records evt and returns the configured error. The client is ignored: nothing reaches a broker.

func (*CapturePublisher[T]) Reset

func (c *CapturePublisher[T]) Reset()

Reset drops the recorded events; the configured error is kept.

Jump to

Keyboard shortcuts

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