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 ¶
- func AssertHandlerRan(t *testing.T, mock *MockInbox, eventID string)
- func AssertNotProcessed(t *testing.T, mock *MockInbox, eventID string)
- func AssertProcessCount(t *testing.T, mock *MockInbox, expected int)
- func AssertProcessed(t *testing.T, mock *MockInbox, eventID string)
- type MockInbox
- func (m *MockInbox) MarkAlreadyProcessed(eventID string) *MockInbox
- func (m *MockInbox) ProcessOnce(ctx context.Context, eventID string, ...) error
- func (m *MockInbox) ProcessedIDs() []string
- func (m *MockInbox) RanIDs() []string
- func (m *MockInbox) Reset()
- func (m *MockInbox) WithError(err error) *MockInbox
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertHandlerRan ¶
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 ¶
AssertNotProcessed asserts that ProcessOnce was never called for the given event id.
func AssertProcessCount ¶
AssertProcessCount asserts the total number of ProcessOnce calls.
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 ¶
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 ¶
ProcessedIDs returns a copy of every eventID passed to ProcessOnce.