helper

package
v1.1.5-beta Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package helper provides testing utilities and log handlers for PostgreSQL event store testing.

This package contains shared testing infrastructure including custom log handlers for capturing and validating log output during tests, and other common test utilities used across the PostgreSQL event store test suite.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterAllEventTypesForOneBook

func FilterAllEventTypesForOneBook(bookID uuid.UUID) eventstore.Filter

FilterAllEventTypesForOneBook creates a filter for all event types for a specific book.

func FilterAllEventTypesForOneBookOrReader

func FilterAllEventTypesForOneBookOrReader(bookID uuid.UUID, readerID uuid.UUID) eventstore.Filter

FilterAllEventTypesForOneBookOrReader creates a filter for book and reader events.

func FixtureBookCopyAddedToCirculation

func FixtureBookCopyAddedToCirculation(bookID uuid.UUID, fakeClock time.Time) core.DomainEvent

FixtureBookCopyAddedToCirculation creates a test event for adding a book to circulation.

func FixtureBookCopyLentToReader

func FixtureBookCopyLentToReader(
	bookID uuid.UUID,
	readerID uuid.UUID,
	fakeClock time.Time,
) core.DomainEvent

FixtureBookCopyLentToReader creates a test event for lending a book to a reader.

func FixtureBookCopyRemovedFromCirculation

func FixtureBookCopyRemovedFromCirculation(bookID uuid.UUID, fakeClock time.Time) core.DomainEvent

FixtureBookCopyRemovedFromCirculation creates a test event for removing a book from circulation.

func FixtureBookCopyReturnedByReader

func FixtureBookCopyReturnedByReader(
	bookID uuid.UUID,
	readerID uuid.UUID,
	fakeClock time.Time,
) core.DomainEvent

FixtureBookCopyReturnedByReader creates a test event for returning a book.

func GivenBookCopyAddedToCirculationWasAppended

func GivenBookCopyAddedToCirculationWasAppended(
	t testing.TB,
	ctx context.Context,
	es postgresengine.EventStore,
	bookID uuid.UUID,
	fakeClock time.Time,
) core.DomainEvent

GivenBookCopyAddedToCirculationWasAppended appends a book addition event for testing.

func GivenBookCopyLentToReaderWasAppended

func GivenBookCopyLentToReaderWasAppended(
	t testing.TB,
	ctx context.Context,
	es postgresengine.EventStore,
	bookID uuid.UUID,
	readerID uuid.UUID,
	fakeClock time.Time,
) core.DomainEvent

GivenBookCopyLentToReaderWasAppended appends a book lending event for testing.

func GivenBookCopyRemovedFromCirculationWasAppended

func GivenBookCopyRemovedFromCirculationWasAppended(
	t testing.TB,
	ctx context.Context,
	es postgresengine.EventStore,
	bookID uuid.UUID,
	fakeClock time.Time,
) core.DomainEvent

GivenBookCopyRemovedFromCirculationWasAppended appends a book removal event for testing.

func GivenBookCopyReturnedByReaderWasAppended

func GivenBookCopyReturnedByReaderWasAppended(
	t testing.TB,
	ctx context.Context,
	es postgresengine.EventStore,
	bookID uuid.UUID,
	readerID uuid.UUID,
	fakeClock time.Time,
) core.DomainEvent

GivenBookCopyReturnedByReaderWasAppended appends a book return event for testing.

func GivenSomeOtherEventsWereAppended

func GivenSomeOtherEventsWereAppended(
	t testing.TB,
	ctx context.Context,
	es postgresengine.EventStore,
	numEvents int,
	startFrom eventstore.MaxSequenceNumberUint,
	fakeClock time.Time,
) time.Time

GivenSomeOtherEventsWereAppended appends random test events to create background data.

func GivenUniqueID

func GivenUniqueID(t testing.TB) uuid.UUID

GivenUniqueID generates a unique UUID for testing.

func QueryMaxSequenceNumberBeforeAppend

func QueryMaxSequenceNumberBeforeAppend(
	t testing.TB,
	ctx context.Context,
	es postgresengine.EventStore,
	filter eventstore.Filter,
) eventstore.MaxSequenceNumberUint

QueryMaxSequenceNumberBeforeAppend queries the current max sequence number for a filter.

func ToStorable

func ToStorable(t testing.TB, domainEvent core.DomainEvent) eventstore.StorableEvent

ToStorable converts a domain event to a storable event for testing.

func ToStorableWithMetadata

func ToStorableWithMetadata(
	t testing.TB,
	domainEvent core.DomainEvent,
	eventMetadata shell.EventMetadata,
) eventstore.StorableEvent

ToStorableWithMetadata converts a domain event to a storable event with metadata.

Types

type LogRecordMatcher

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

LogRecordMatcher provides a fluent interface for checking log record attributes.

func (*LogRecordMatcher) Assert

func (m *LogRecordMatcher) Assert() bool

Assert returns true if all conditions in the fluent chain were met.

func (*LogRecordMatcher) WithDurationMS

func (m *LogRecordMatcher) WithDurationMS() *LogRecordMatcher

WithDurationMS checks if the log record has a duration_ms attribute with a non-negative value.

func (*LogRecordMatcher) WithEventCount

func (m *LogRecordMatcher) WithEventCount() *LogRecordMatcher

WithEventCount checks if the log record has an event_count attribute with a non-negative value.

func (*LogRecordMatcher) WithExpectedEvents

func (m *LogRecordMatcher) WithExpectedEvents() *LogRecordMatcher

WithExpectedEvents checks if the log record has an expected_events attribute with a non-negative value.

func (*LogRecordMatcher) WithExpectedSequence

func (m *LogRecordMatcher) WithExpectedSequence() *LogRecordMatcher

WithExpectedSequence checks if the log record has an expected_sequence attribute with a non-negative value.

func (*LogRecordMatcher) WithRowsAffected

func (m *LogRecordMatcher) WithRowsAffected() *LogRecordMatcher

WithRowsAffected checks if the log record has a rows_affected attribute with a non-negative value.

type TestLogHandler

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

TestLogHandler is a slog.Handler implementation that captures log records for testing.

func NewTestLogHandler

func NewTestLogHandler(logToStdOut bool) *TestLogHandler

NewTestLogHandler creates a new TestLogHandler Switchable to log to stdout, which can be useful for debugging tests by seeing the actual log output.

func (*TestLogHandler) Enabled

func (h *TestLogHandler) Enabled(_ context.Context, _ slog.Level) bool

Enabled implements slog.Handler interface.

func (*TestLogHandler) GetRecordCount

func (h *TestLogHandler) GetRecordCount() int

GetRecordCount returns the number of captured log records.

func (*TestLogHandler) GetRecords

func (h *TestLogHandler) GetRecords() []slog.Record

GetRecords returns a copy of all captured log records.

func (*TestLogHandler) Handle

func (h *TestLogHandler) Handle(ctx context.Context, record slog.Record) error

Handle implements slog.Handler interface.

func (*TestLogHandler) HasDebugLog

func (h *TestLogHandler) HasDebugLog(message string) bool

HasDebugLog checks if there's a debug-level log record containing the specified message.

func (*TestLogHandler) HasDebugLogWithDurationMS

func (h *TestLogHandler) HasDebugLogWithDurationMS(message string) bool

HasDebugLogWithDurationMS checks if there is a debug-level log record with the specified message that contains a duration_ms attribute with a non-negative value Deprecated: Use HasDebugLogWithMessage(msg).WithDurationMS().Assert() instead.

func (*TestLogHandler) HasDebugLogWithDurationNS

func (h *TestLogHandler) HasDebugLogWithDurationNS(message string) bool

HasDebugLogWithDurationNS checks if there is a debug-level log record with the specified message that contains a duration_ns attribute with a non-negative value.

func (*TestLogHandler) HasDebugLogWithMessage

func (h *TestLogHandler) HasDebugLogWithMessage(message string) *LogRecordMatcher

HasDebugLogWithMessage starts a fluent chain to check a debug-level log record.

func (*TestLogHandler) HasInfoLogWithDurationMS

func (h *TestLogHandler) HasInfoLogWithDurationMS(message string) bool

HasInfoLogWithDurationMS checks if there is an info-level log record with the specified message that contains a duration_ms attribute with a non-negative value Deprecated: Use HasInfoLogWithMessage(msg).WithDurationMS().Assert() instead.

func (*TestLogHandler) HasInfoLogWithMessage

func (h *TestLogHandler) HasInfoLogWithMessage(message string) *LogRecordMatcher

HasInfoLogWithMessage starts a fluent chain to check an info-level log record.

func (*TestLogHandler) Reset

func (h *TestLogHandler) Reset()

Reset clears all captured log records.

func (*TestLogHandler) WithAttrs

func (h *TestLogHandler) WithAttrs(_ []slog.Attr) slog.Handler

WithAttrs implements slog.Handler interface.

func (*TestLogHandler) WithGroup

func (h *TestLogHandler) WithGroup(_ string) slog.Handler

WithGroup implements slog.Handler interface.

Directories

Path Synopsis
Package postgreswrapper provides test utilities for abstracting over different PostgreSQL database adapters.
Package postgreswrapper provides test utilities for abstracting over different PostgreSQL database adapters.

Jump to

Keyboard shortcuts

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