testing

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package testing provides test utilities for the consumer-side inbox.

MockInbox implements app.InboxProcessor for unit testing, letting application developers verify exactly-once handler logic without a real database.

Usage:

mockInbox := inboxtest.NewMockInbox()
handler := NewHandler(mockInbox)
handler.Handle(ctx, delivery)
inboxtest.AssertProcessed(t, mockInbox, "evt-1")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertHandlerRan

func AssertHandlerRan(t *testing.T, mock *MockInbox, eventID string)

AssertHandlerRan asserts that the handler (fn) actually executed for the given event id (i.e. it was a first-time, non-error processing).

func AssertNotProcessed

func AssertNotProcessed(t *testing.T, mock *MockInbox, eventID string)

AssertNotProcessed asserts that ProcessOnce was never called for the given event id.

func AssertProcessCount

func AssertProcessCount(t *testing.T, mock *MockInbox, expected int)

AssertProcessCount asserts the total number of ProcessOnce calls.

func AssertProcessed

func AssertProcessed(t *testing.T, mock *MockInbox, eventID string)

AssertProcessed asserts that ProcessOnce was called for the given event id.

Types

type MockInbox

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

MockInbox implements app.InboxProcessor for unit testing. It records every ProcessOnce call, auto-deduplicates repeated event ids (the second call with the same id skips fn, like the real inbox), and supports a configurable error and pre-marked already-processed ids.

Thread-safe: all operations use sync.Mutex for concurrent test scenarios.

func NewMockInbox

func NewMockInbox() *MockInbox

NewMockInbox creates a new MockInbox with no configured failures.

func (*MockInbox) MarkAlreadyProcessed

func (m *MockInbox) MarkAlreadyProcessed(eventID string) *MockInbox

MarkAlreadyProcessed pre-marks eventID as processed, so the next ProcessOnce for that id treats it as a duplicate and skips fn.

func (*MockInbox) ProcessOnce

func (m *MockInbox) ProcessOnce(ctx context.Context, eventID string, fn func(ctx context.Context, tx dbtypes.Tx) error) error

ProcessOnce implements app.InboxProcessor. It records the call and runs fn (with a nil tx) exactly once per eventID, unless an error is configured or the id was already processed.

func (*MockInbox) ProcessedIDs

func (m *MockInbox) ProcessedIDs() []string

ProcessedIDs returns a copy of every eventID passed to ProcessOnce.

func (*MockInbox) RanIDs

func (m *MockInbox) RanIDs() []string

RanIDs returns a copy of the eventIDs whose fn was actually executed (excludes duplicates and error short-circuits).

func (*MockInbox) Reset

func (m *MockInbox) Reset()

Reset clears all recorded state.

func (*MockInbox) WithError

func (m *MockInbox) WithError(err error) *MockInbox

WithError configures the mock to return err from every ProcessOnce call (without running fn). Useful for testing handler error paths.

Jump to

Keyboard shortcuts

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