testing

package
v0.71.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 5 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.

type CaptureSealedPublisher added in v0.70.0

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

CaptureSealedPublisher is a concurrency-safe SealedEventPublisher[T] double that records calls and never seals, verifies or publishes.

func NewCaptureSealedPublisher added in v0.70.0

func NewCaptureSealedPublisher[T any]() *CaptureSealedPublisher[T]

NewCaptureSealedPublisher returns an empty capture whose Seal and PublishSealed succeed.

func (*CaptureSealedPublisher[T]) FailPublish added in v0.70.0

func (c *CaptureSealedPublisher[T]) FailPublish(err error)

FailPublish makes every later PublishSealed return err (nil restores success).

func (*CaptureSealedPublisher[T]) FailSeal added in v0.70.0

func (c *CaptureSealedPublisher[T]) FailSeal(err error)

FailSeal makes every later Seal return err (nil restores success).

func (*CaptureSealedPublisher[T]) PublishSealed added in v0.70.0

func (c *CaptureSealedPublisher[T]) PublishSealed(_ context.Context, _ messaging.AMQPClient, data []byte) error

PublishSealed records a copy of data and returns the error FailPublish configured.

func (*CaptureSealedPublisher[T]) Published added in v0.70.0

func (c *CaptureSealedPublisher[T]) Published() [][]byte

Published returns every body handed to PublishSealed, oldest first, as copies the caller owns.

func (*CaptureSealedPublisher[T]) Reset added in v0.70.0

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

Reset drops the records and restarts the placeholder counter; configured errors are kept.

func (*CaptureSealedPublisher[T]) Seal added in v0.70.0

func (c *CaptureSealedPublisher[T]) Seal(_ context.Context, evt T) (data []byte, jti string, err error)

Seal records evt and returns "sealed-<n>" and "jti-<n>", or the error FailSeal configured.

func (*CaptureSealedPublisher[T]) Sealed added in v0.70.0

func (c *CaptureSealedPublisher[T]) Sealed() []T

Sealed returns every event handed to Seal, oldest first, as a copy the caller owns.

Jump to

Keyboard shortcuts

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