Documentation
¶
Overview ¶
Package helper provides testing utilities, log handlers, and metrics collectors for PostgreSQL event store testing.
This package contains shared testing infrastructure including: - Custom log handlers for capturing and validating log output during tests - OpenTelemetry-compatible metrics collectors for testing observability instrumentation - Common test utilities used across the PostgreSQL event store test suite
The metrics testing infrastructure follows OpenTelemetry standards, making it suitable for testing EventStore observability features that are compatible with modern observability platforms.
Index ¶
- func FilterAllEventTypesForOneBook(bookID uuid.UUID) eventstore.Filter
- func FilterAllEventTypesForOneBookOrReader(bookID uuid.UUID, readerID uuid.UUID) eventstore.Filter
- func FixtureBookCopyAddedToCirculation(bookID uuid.UUID, fakeClock time.Time) core.DomainEvent
- func FixtureBookCopyLentToReader(bookID uuid.UUID, readerID uuid.UUID, fakeClock time.Time) core.DomainEvent
- func FixtureBookCopyRemovedFromCirculation(bookID uuid.UUID, fakeClock time.Time) core.DomainEvent
- func FixtureBookCopyReturnedByReader(bookID uuid.UUID, readerID uuid.UUID, fakeClock time.Time) core.DomainEvent
- func GivenBookCopyAddedToCirculationWasAppended(t testing.TB, ctx context.Context, es postgresengine.EventStore, ...) core.DomainEvent
- func GivenBookCopyLentToReaderWasAppended(t testing.TB, ctx context.Context, es postgresengine.EventStore, ...) core.DomainEvent
- func GivenBookCopyRemovedFromCirculationWasAppended(t testing.TB, ctx context.Context, es postgresengine.EventStore, ...) core.DomainEvent
- func GivenBookCopyReturnedByReaderWasAppended(t testing.TB, ctx context.Context, es postgresengine.EventStore, ...) core.DomainEvent
- func GivenSomeOtherEventsWereAppended(t testing.TB, ctx context.Context, es postgresengine.EventStore, numEvents int, ...) time.Time
- func GivenUniqueID(t testing.TB) uuid.UUID
- func QueryMaxSequenceNumberBeforeAppend(t testing.TB, ctx context.Context, es postgresengine.EventStore, ...) eventstore.MaxSequenceNumberUint
- func ToStorable(t testing.TB, domainEvent core.DomainEvent) eventstore.StorableEvent
- func ToStorableWithMetadata(t testing.TB, domainEvent core.DomainEvent, eventMetadata shell.EventMetadata) eventstore.StorableEvent
- type CounterRecord
- type DurationRecord
- type LogRecordMatcher
- func (m *LogRecordMatcher) Assert() bool
- func (m *LogRecordMatcher) WithDurationMS() *LogRecordMatcher
- func (m *LogRecordMatcher) WithEventCount() *LogRecordMatcher
- func (m *LogRecordMatcher) WithExpectedEvents() *LogRecordMatcher
- func (m *LogRecordMatcher) WithExpectedSequence() *LogRecordMatcher
- func (m *LogRecordMatcher) WithRowsAffected() *LogRecordMatcher
- type MetricRecordMatcher
- func (m *MetricRecordMatcher) Assert() bool
- func (m *MetricRecordMatcher) WithConflictType(conflictType string) *MetricRecordMatcher
- func (m *MetricRecordMatcher) WithErrorType(errorType string) *MetricRecordMatcher
- func (m *MetricRecordMatcher) WithLabel(key, value string) *MetricRecordMatcher
- func (m *MetricRecordMatcher) WithOperation(operation string) *MetricRecordMatcher
- func (m *MetricRecordMatcher) WithStatus(status string) *MetricRecordMatcher
- type TestLogHandler
- func (h *TestLogHandler) Enabled(_ context.Context, _ slog.Level) bool
- func (h *TestLogHandler) GetRecordCount() int
- func (h *TestLogHandler) GetRecords() []slog.Record
- func (h *TestLogHandler) Handle(ctx context.Context, record slog.Record) error
- func (h *TestLogHandler) HasDebugLog(message string) bool
- func (h *TestLogHandler) HasDebugLogWithDurationMS(message string) bool
- func (h *TestLogHandler) HasDebugLogWithDurationNS(message string) bool
- func (h *TestLogHandler) HasDebugLogWithMessage(message string) *LogRecordMatcher
- func (h *TestLogHandler) HasInfoLogWithDurationMS(message string) bool
- func (h *TestLogHandler) HasInfoLogWithMessage(message string) *LogRecordMatcher
- func (h *TestLogHandler) Reset()
- func (h *TestLogHandler) WithAttrs(_ []slog.Attr) slog.Handler
- func (h *TestLogHandler) WithGroup(_ string) slog.Handler
- type TestMetricsCollector
- func (c *TestMetricsCollector) CountCounterRecordsForMetric(metric string) int
- func (c *TestMetricsCollector) CountDurationRecordsForMetric(metric string) int
- func (c *TestMetricsCollector) CountValueRecordsForMetric(metric string) int
- func (c *TestMetricsCollector) GetCounterRecordCount() int
- func (c *TestMetricsCollector) GetCounterRecords() []CounterRecord
- func (c *TestMetricsCollector) GetDurationRecordCount() int
- func (c *TestMetricsCollector) GetDurationRecords() []DurationRecord
- func (c *TestMetricsCollector) GetValueRecordCount() int
- func (c *TestMetricsCollector) GetValueRecords() []ValueRecord
- func (c *TestMetricsCollector) HasCounterRecord(metric string) bool
- func (c *TestMetricsCollector) HasCounterRecordForMetric(metric string) *MetricRecordMatcher
- func (c *TestMetricsCollector) HasDurationRecord(metric string) bool
- func (c *TestMetricsCollector) HasDurationRecordForMetric(metric string) *MetricRecordMatcher
- func (c *TestMetricsCollector) HasValueRecord(metric string) bool
- func (c *TestMetricsCollector) HasValueRecordForMetric(metric string) *MetricRecordMatcher
- func (c *TestMetricsCollector) IncrementCounter(metric string, labels map[string]string)
- func (c *TestMetricsCollector) RecordDuration(metric string, duration time.Duration, labels map[string]string)
- func (c *TestMetricsCollector) RecordValue(metric string, value float64, labels map[string]string)
- func (c *TestMetricsCollector) Reset()
- type ValueRecord
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 ¶
FilterAllEventTypesForOneBookOrReader creates a filter for book and reader events.
func FixtureBookCopyAddedToCirculation ¶
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 ¶
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 ¶
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 CounterRecord ¶
CounterRecord represents a recorded counter-increment call.
type DurationRecord ¶
DurationRecord represents a recorded duration metric call.
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 MetricRecordMatcher ¶
type MetricRecordMatcher struct {
// contains filtered or unexported fields
}
MetricRecordMatcher provides a fluent interface for checking metric records.
func (*MetricRecordMatcher) Assert ¶
func (m *MetricRecordMatcher) Assert() bool
Assert returns true if all conditions in the fluent chain were met.
func (*MetricRecordMatcher) WithConflictType ¶
func (m *MetricRecordMatcher) WithConflictType(conflictType string) *MetricRecordMatcher
WithConflictType checks if the record has the specified conflict_type label.
func (*MetricRecordMatcher) WithErrorType ¶
func (m *MetricRecordMatcher) WithErrorType(errorType string) *MetricRecordMatcher
WithErrorType checks if the record has the specified error_type label.
func (*MetricRecordMatcher) WithLabel ¶
func (m *MetricRecordMatcher) WithLabel(key, value string) *MetricRecordMatcher
WithLabel checks if the record has the specified label with the given value.
func (*MetricRecordMatcher) WithOperation ¶
func (m *MetricRecordMatcher) WithOperation(operation string) *MetricRecordMatcher
WithOperation checks if the record has the specified operation label.
func (*MetricRecordMatcher) WithStatus ¶
func (m *MetricRecordMatcher) WithStatus(status string) *MetricRecordMatcher
WithStatus checks if the record has the specified status label.
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) 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) 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.
type TestMetricsCollector ¶
type TestMetricsCollector struct {
// contains filtered or unexported fields
}
TestMetricsCollector is a MetricsCollector implementation that captures metrics calls for testing. It implements the same interface as OpenTelemetry metrics collectors, making it suitable for testing EventStore observability instrumentation that follows OpenTelemetry standards.
func NewTestMetricsCollector ¶
func NewTestMetricsCollector(recordCalls bool) *TestMetricsCollector
NewTestMetricsCollector creates a new TestMetricsCollector for testing OpenTelemetry-compatible metrics. Set recordCalls to true to capture all metrics calls for inspection in tests.
func (*TestMetricsCollector) CountCounterRecordsForMetric ¶
func (c *TestMetricsCollector) CountCounterRecordsForMetric(metric string) int
CountCounterRecordsForMetric counts how many counter-records exist for a specific metric.
func (*TestMetricsCollector) CountDurationRecordsForMetric ¶
func (c *TestMetricsCollector) CountDurationRecordsForMetric(metric string) int
CountDurationRecordsForMetric counts how many duration records exist for a specific metric.
func (*TestMetricsCollector) CountValueRecordsForMetric ¶
func (c *TestMetricsCollector) CountValueRecordsForMetric(metric string) int
CountValueRecordsForMetric counts how many value records exist for a specific metric.
func (*TestMetricsCollector) GetCounterRecordCount ¶
func (c *TestMetricsCollector) GetCounterRecordCount() int
GetCounterRecordCount returns the number of captured counter-records.
func (*TestMetricsCollector) GetCounterRecords ¶
func (c *TestMetricsCollector) GetCounterRecords() []CounterRecord
GetCounterRecords returns a copy of all captured counter-records.
func (*TestMetricsCollector) GetDurationRecordCount ¶
func (c *TestMetricsCollector) GetDurationRecordCount() int
GetDurationRecordCount returns the number of captured duration records.
func (*TestMetricsCollector) GetDurationRecords ¶
func (c *TestMetricsCollector) GetDurationRecords() []DurationRecord
GetDurationRecords returns a copy of all captured duration records.
func (*TestMetricsCollector) GetValueRecordCount ¶
func (c *TestMetricsCollector) GetValueRecordCount() int
GetValueRecordCount returns the number of captured value records.
func (*TestMetricsCollector) GetValueRecords ¶
func (c *TestMetricsCollector) GetValueRecords() []ValueRecord
GetValueRecords returns a copy of all captured value records.
func (*TestMetricsCollector) HasCounterRecord ¶
func (c *TestMetricsCollector) HasCounterRecord(metric string) bool
HasCounterRecord checks if there's a counter-record with the specified metric name.
func (*TestMetricsCollector) HasCounterRecordForMetric ¶
func (c *TestMetricsCollector) HasCounterRecordForMetric(metric string) *MetricRecordMatcher
HasCounterRecordForMetric starts a fluent chain to check a counter-record.
func (*TestMetricsCollector) HasDurationRecord ¶
func (c *TestMetricsCollector) HasDurationRecord(metric string) bool
HasDurationRecord checks if there's a duration record with the specified metric name.
func (*TestMetricsCollector) HasDurationRecordForMetric ¶
func (c *TestMetricsCollector) HasDurationRecordForMetric(metric string) *MetricRecordMatcher
HasDurationRecordForMetric starts a fluent chain to check a duration record.
func (*TestMetricsCollector) HasValueRecord ¶
func (c *TestMetricsCollector) HasValueRecord(metric string) bool
HasValueRecord checks if there's a value record with the specified metric name.
func (*TestMetricsCollector) HasValueRecordForMetric ¶
func (c *TestMetricsCollector) HasValueRecordForMetric(metric string) *MetricRecordMatcher
HasValueRecordForMetric starts a fluent chain to check a value record.
func (*TestMetricsCollector) IncrementCounter ¶
func (c *TestMetricsCollector) IncrementCounter(metric string, labels map[string]string)
IncrementCounter implements the MetricsCollector interface for OpenTelemetry-compatible counter metrics.
func (*TestMetricsCollector) RecordDuration ¶
func (c *TestMetricsCollector) RecordDuration(metric string, duration time.Duration, labels map[string]string)
RecordDuration implements the MetricsCollector interface for OpenTelemetry-compatible duration metrics.
func (*TestMetricsCollector) RecordValue ¶
func (c *TestMetricsCollector) RecordValue(metric string, value float64, labels map[string]string)
RecordValue implements the MetricsCollector interface for OpenTelemetry-compatible value/gauge metrics.
func (*TestMetricsCollector) Reset ¶
func (c *TestMetricsCollector) Reset()
Reset clears all captured metric records.
Source Files
¶
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. |