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, ...) 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 ContextualLoggerSpy
- func (s *ContextualLoggerSpy) DebugContext(ctx context.Context, msg string, args ...any)
- func (s *ContextualLoggerSpy) ErrorContext(ctx context.Context, msg string, args ...any)
- func (s *ContextualLoggerSpy) GetDebugRecords() []SpyContextualLogRecord
- func (s *ContextualLoggerSpy) GetErrorRecords() []SpyContextualLogRecord
- func (s *ContextualLoggerSpy) GetInfoRecords() []SpyContextualLogRecord
- func (s *ContextualLoggerSpy) GetTotalRecordCount() int
- func (s *ContextualLoggerSpy) GetWarnRecords() []SpyContextualLogRecord
- func (s *ContextualLoggerSpy) HasDebugLog(message string) bool
- func (s *ContextualLoggerSpy) HasErrorLog(message string) bool
- func (s *ContextualLoggerSpy) HasInfoLog(message string) bool
- func (s *ContextualLoggerSpy) InfoContext(ctx context.Context, msg string, args ...any)
- func (s *ContextualLoggerSpy) Reset()
- func (s *ContextualLoggerSpy) WarnContext(ctx context.Context, msg string, args ...any)
- type LogHandlerSpy
- func (s *LogHandlerSpy) Enabled(_ context.Context, _ slog.Level) bool
- func (s *LogHandlerSpy) GetRecordCount() int
- func (s *LogHandlerSpy) GetRecords() []slog.Record
- func (s *LogHandlerSpy) Handle(ctx context.Context, record slog.Record) error
- func (s *LogHandlerSpy) HasDebugLog(message string) bool
- func (s *LogHandlerSpy) HasDebugLogWithDurationMS(message string) bool
- func (s *LogHandlerSpy) HasDebugLogWithDurationNS(message string) bool
- func (s *LogHandlerSpy) HasDebugLogWithMessage(message string) *SpyLogRecordMatcher
- func (s *LogHandlerSpy) HasErrorLog(message string) bool
- func (s *LogHandlerSpy) HasErrorLogWithMessage(message string) *SpyLogRecordMatcher
- func (s *LogHandlerSpy) HasInfoLogWithDurationMS(message string) bool
- func (s *LogHandlerSpy) HasInfoLogWithMessage(message string) *SpyLogRecordMatcher
- func (s *LogHandlerSpy) HasWarnLog(message string) bool
- func (s *LogHandlerSpy) HasWarnLogWithMessage(message string) *SpyLogRecordMatcher
- func (s *LogHandlerSpy) Reset()
- func (s *LogHandlerSpy) WithAttrs(_ []slog.Attr) slog.Handler
- func (s *LogHandlerSpy) WithGroup(_ string) slog.Handler
- 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 MetricsCollectorSpy
- func (s *MetricsCollectorSpy) CountCounterRecordsForMetric(metric string) int
- func (s *MetricsCollectorSpy) CountDurationRecordsForMetric(metric string) int
- func (s *MetricsCollectorSpy) CountValueRecordsForMetric(metric string) int
- func (s *MetricsCollectorSpy) GetCounterRecordCount() int
- func (s *MetricsCollectorSpy) GetCounterRecords() []SpyCounterRecord
- func (s *MetricsCollectorSpy) GetDurationRecordCount() int
- func (s *MetricsCollectorSpy) GetDurationRecords() []SpyDurationRecord
- func (s *MetricsCollectorSpy) GetValueRecordCount() int
- func (s *MetricsCollectorSpy) GetValueRecords() []SpyValueRecord
- func (s *MetricsCollectorSpy) HasCounterRecord(metric string) bool
- func (s *MetricsCollectorSpy) HasCounterRecordForMetric(metric string) *MetricRecordMatcher
- func (s *MetricsCollectorSpy) HasDurationRecord(metric string) bool
- func (s *MetricsCollectorSpy) HasDurationRecordForMetric(metric string) *MetricRecordMatcher
- func (s *MetricsCollectorSpy) HasValueRecord(metric string) bool
- func (s *MetricsCollectorSpy) HasValueRecordForMetric(metric string) *MetricRecordMatcher
- func (s *MetricsCollectorSpy) IncrementCounter(metric string, labels map[string]string)
- func (s *MetricsCollectorSpy) IncrementCounterContext(_ context.Context, metric string, labels map[string]string)
- func (s *MetricsCollectorSpy) RecordDuration(metric string, duration time.Duration, labels map[string]string)
- func (s *MetricsCollectorSpy) RecordDurationContext(_ context.Context, metric string, duration time.Duration, ...)
- func (s *MetricsCollectorSpy) RecordValue(metric string, value float64, labels map[string]string)
- func (s *MetricsCollectorSpy) RecordValueContext(_ context.Context, metric string, value float64, labels map[string]string)
- func (s *MetricsCollectorSpy) Reset()
- func (s *MetricsCollectorSpy) SupportsContextual() bool
- type SpanRecordMatcher
- func (m *SpanRecordMatcher) Assert() bool
- func (m *SpanRecordMatcher) WithEndAttribute(key, value string) *SpanRecordMatcher
- func (m *SpanRecordMatcher) WithSpanAttribute(key, value string) *SpanRecordMatcher
- func (m *SpanRecordMatcher) WithStartAttribute(key, value string) *SpanRecordMatcher
- func (m *SpanRecordMatcher) WithStatus(status string) *SpanRecordMatcher
- type SpyContextualLogRecord
- type SpyCounterRecord
- type SpyDurationRecord
- type SpyLogRecordMatcher
- func (m *SpyLogRecordMatcher) Assert() bool
- func (m *SpyLogRecordMatcher) WithDurationMS() *SpyLogRecordMatcher
- func (m *SpyLogRecordMatcher) WithEventCount() *SpyLogRecordMatcher
- func (m *SpyLogRecordMatcher) WithExpectedEvents() *SpyLogRecordMatcher
- func (m *SpyLogRecordMatcher) WithExpectedSequence() *SpyLogRecordMatcher
- func (m *SpyLogRecordMatcher) WithRowsAffected() *SpyLogRecordMatcher
- type SpySpanContext
- type SpySpanRecord
- type SpyValueRecord
- type TracingCollectorSpy
- func (s *TracingCollectorSpy) CountSpanRecordsForName(name string) int
- func (s *TracingCollectorSpy) FinishSpan(spanCtx postgresengine.SpanContext, status string, attrs map[string]string)
- func (s *TracingCollectorSpy) GetSpanRecordCount() int
- func (s *TracingCollectorSpy) GetSpanRecords() []SpySpanRecord
- func (s *TracingCollectorSpy) HasSpanRecord(name string) bool
- func (s *TracingCollectorSpy) HasSpanRecordForName(name string) *SpanRecordMatcher
- func (s *TracingCollectorSpy) Reset()
- func (s *TracingCollectorSpy) StartSpan(ctx context.Context, name string, attrs map[string]string) (context.Context, postgresengine.SpanContext)
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 ContextualLoggerSpy ¶
type ContextualLoggerSpy struct {
// contains filtered or unexported fields
}
ContextualLoggerSpy is a ContextualLogger implementation that captures contextual logging calls for testing. It implements the same interface as OpenTelemetry loggers, making it suitable for testing EventStore observability instrumentation that follows OpenTelemetry standards.
func NewContextualLoggerSpy ¶
func NewContextualLoggerSpy(recordCalls bool) *ContextualLoggerSpy
NewContextualLoggerSpy creates a new ContextualLoggerSpy instance.
func (*ContextualLoggerSpy) DebugContext ¶
func (s *ContextualLoggerSpy) DebugContext(ctx context.Context, msg string, args ...any)
DebugContext implements the ContextualLogger interface for testing.
func (*ContextualLoggerSpy) ErrorContext ¶
func (s *ContextualLoggerSpy) ErrorContext(ctx context.Context, msg string, args ...any)
ErrorContext implements the ContextualLogger interface for testing.
func (*ContextualLoggerSpy) GetDebugRecords ¶
func (s *ContextualLoggerSpy) GetDebugRecords() []SpyContextualLogRecord
GetDebugRecords returns a copy of all debug log records.
func (*ContextualLoggerSpy) GetErrorRecords ¶
func (s *ContextualLoggerSpy) GetErrorRecords() []SpyContextualLogRecord
GetErrorRecords returns a copy of all error log records.
func (*ContextualLoggerSpy) GetInfoRecords ¶
func (s *ContextualLoggerSpy) GetInfoRecords() []SpyContextualLogRecord
GetInfoRecords returns a copy of all info log records.
func (*ContextualLoggerSpy) GetTotalRecordCount ¶
func (s *ContextualLoggerSpy) GetTotalRecordCount() int
GetTotalRecordCount returns the total number of log records across all levels.
func (*ContextualLoggerSpy) GetWarnRecords ¶
func (s *ContextualLoggerSpy) GetWarnRecords() []SpyContextualLogRecord
GetWarnRecords returns a copy of all warn log records.
func (*ContextualLoggerSpy) HasDebugLog ¶
func (s *ContextualLoggerSpy) HasDebugLog(message string) bool
HasDebugLog checks if a debug log with the specified message exists.
func (*ContextualLoggerSpy) HasErrorLog ¶
func (s *ContextualLoggerSpy) HasErrorLog(message string) bool
HasErrorLog checks if an error log with the specified message exists.
func (*ContextualLoggerSpy) HasInfoLog ¶
func (s *ContextualLoggerSpy) HasInfoLog(message string) bool
HasInfoLog checks if an info log with the specified message exists.
func (*ContextualLoggerSpy) InfoContext ¶
func (s *ContextualLoggerSpy) InfoContext(ctx context.Context, msg string, args ...any)
InfoContext implements the ContextualLogger interface for testing.
func (*ContextualLoggerSpy) Reset ¶
func (s *ContextualLoggerSpy) Reset()
Reset clears all recorded log calls.
func (*ContextualLoggerSpy) WarnContext ¶
func (s *ContextualLoggerSpy) WarnContext(ctx context.Context, msg string, args ...any)
WarnContext implements the ContextualLogger interface for testing.
type LogHandlerSpy ¶
type LogHandlerSpy struct {
// contains filtered or unexported fields
}
LogHandlerSpy is a slog.Handler implementation that captures log records for testing.
func NewLogHandlerSpy ¶
func NewLogHandlerSpy(logToStdOut bool) *LogHandlerSpy
NewLogHandlerSpy creates a new LogHandlerSpy Switchable to log to stdout, which can be useful for debugging tests by seeing the actual log output.
func (*LogHandlerSpy) GetRecordCount ¶
func (s *LogHandlerSpy) GetRecordCount() int
GetRecordCount returns the number of captured log records.
func (*LogHandlerSpy) GetRecords ¶
func (s *LogHandlerSpy) GetRecords() []slog.Record
GetRecords returns a copy of all captured log records.
func (*LogHandlerSpy) HasDebugLog ¶
func (s *LogHandlerSpy) HasDebugLog(message string) bool
HasDebugLog checks if there's a debug-level log record containing the specified message.
func (*LogHandlerSpy) HasDebugLogWithDurationMS ¶
func (s *LogHandlerSpy) 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 (*LogHandlerSpy) HasDebugLogWithDurationNS ¶
func (s *LogHandlerSpy) 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 (*LogHandlerSpy) HasDebugLogWithMessage ¶
func (s *LogHandlerSpy) HasDebugLogWithMessage(message string) *SpyLogRecordMatcher
HasDebugLogWithMessage starts a fluent chain to check a debug-level log record.
func (*LogHandlerSpy) HasErrorLog ¶
func (s *LogHandlerSpy) HasErrorLog(message string) bool
HasErrorLog checks if there's an error-level log record containing the specified message.
func (*LogHandlerSpy) HasErrorLogWithMessage ¶
func (s *LogHandlerSpy) HasErrorLogWithMessage(message string) *SpyLogRecordMatcher
HasErrorLogWithMessage starts a fluent chain to check an error-level log record.
func (*LogHandlerSpy) HasInfoLogWithDurationMS ¶
func (s *LogHandlerSpy) 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 (*LogHandlerSpy) HasInfoLogWithMessage ¶
func (s *LogHandlerSpy) HasInfoLogWithMessage(message string) *SpyLogRecordMatcher
HasInfoLogWithMessage starts a fluent chain to check an info-level log record.
func (*LogHandlerSpy) HasWarnLog ¶
func (s *LogHandlerSpy) HasWarnLog(message string) bool
HasWarnLog checks if there's a warn-level log record containing the specified message.
func (*LogHandlerSpy) HasWarnLogWithMessage ¶
func (s *LogHandlerSpy) HasWarnLogWithMessage(message string) *SpyLogRecordMatcher
HasWarnLogWithMessage starts a fluent chain to check a warn-level log record.
func (*LogHandlerSpy) Reset ¶
func (s *LogHandlerSpy) Reset()
Reset clears all captured log records.
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 MetricsCollectorSpy ¶
type MetricsCollectorSpy struct {
// contains filtered or unexported fields
}
MetricsCollectorSpy 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. When supportsContextual is true, it also implements ContextualMetricsCollector.
func NewContextualMetricsCollectorSpy ¶
func NewContextualMetricsCollectorSpy(recordCalls bool) *MetricsCollectorSpy
NewContextualMetricsCollectorSpy creates a new MetricsCollectorSpy that implements ContextualMetricsCollector. Set recordCalls to true to capture all metrics calls for inspection in tests.
func NewMetricsCollectorSpy ¶
func NewMetricsCollectorSpy(recordCalls bool) *MetricsCollectorSpy
NewMetricsCollectorSpy creates a new MetricsCollectorSpy for testing OpenTelemetry-compatible metrics. Set recordCalls to true to capture all metrics calls for inspection in tests.
func (*MetricsCollectorSpy) CountCounterRecordsForMetric ¶
func (s *MetricsCollectorSpy) CountCounterRecordsForMetric(metric string) int
CountCounterRecordsForMetric counts how many counter records exist for a specific metric.
func (*MetricsCollectorSpy) CountDurationRecordsForMetric ¶
func (s *MetricsCollectorSpy) CountDurationRecordsForMetric(metric string) int
CountDurationRecordsForMetric counts how many duration records exist for a specific metric.
func (*MetricsCollectorSpy) CountValueRecordsForMetric ¶
func (s *MetricsCollectorSpy) CountValueRecordsForMetric(metric string) int
CountValueRecordsForMetric counts how many value records exist for a specific metric.
func (*MetricsCollectorSpy) GetCounterRecordCount ¶
func (s *MetricsCollectorSpy) GetCounterRecordCount() int
GetCounterRecordCount returns the number of captured counter records.
func (*MetricsCollectorSpy) GetCounterRecords ¶
func (s *MetricsCollectorSpy) GetCounterRecords() []SpyCounterRecord
GetCounterRecords returns a copy of all captured counter records.
func (*MetricsCollectorSpy) GetDurationRecordCount ¶
func (s *MetricsCollectorSpy) GetDurationRecordCount() int
GetDurationRecordCount returns the number of captured duration records.
func (*MetricsCollectorSpy) GetDurationRecords ¶
func (s *MetricsCollectorSpy) GetDurationRecords() []SpyDurationRecord
GetDurationRecords returns a copy of all captured duration records.
func (*MetricsCollectorSpy) GetValueRecordCount ¶
func (s *MetricsCollectorSpy) GetValueRecordCount() int
GetValueRecordCount returns the number of captured value records.
func (*MetricsCollectorSpy) GetValueRecords ¶
func (s *MetricsCollectorSpy) GetValueRecords() []SpyValueRecord
GetValueRecords returns a copy of all captured value records.
func (*MetricsCollectorSpy) HasCounterRecord ¶
func (s *MetricsCollectorSpy) HasCounterRecord(metric string) bool
HasCounterRecord checks if there's a counter record with the specified metric name.
func (*MetricsCollectorSpy) HasCounterRecordForMetric ¶
func (s *MetricsCollectorSpy) HasCounterRecordForMetric(metric string) *MetricRecordMatcher
HasCounterRecordForMetric starts a fluent chain to check a counter record.
func (*MetricsCollectorSpy) HasDurationRecord ¶
func (s *MetricsCollectorSpy) HasDurationRecord(metric string) bool
HasDurationRecord checks if there's a duration record with the specified metric name.
func (*MetricsCollectorSpy) HasDurationRecordForMetric ¶
func (s *MetricsCollectorSpy) HasDurationRecordForMetric(metric string) *MetricRecordMatcher
HasDurationRecordForMetric starts a fluent chain to check a duration record.
func (*MetricsCollectorSpy) HasValueRecord ¶
func (s *MetricsCollectorSpy) HasValueRecord(metric string) bool
HasValueRecord checks if there's a value record with the specified metric name.
func (*MetricsCollectorSpy) HasValueRecordForMetric ¶
func (s *MetricsCollectorSpy) HasValueRecordForMetric(metric string) *MetricRecordMatcher
HasValueRecordForMetric starts a fluent chain to check a value record.
func (*MetricsCollectorSpy) IncrementCounter ¶
func (s *MetricsCollectorSpy) IncrementCounter(metric string, labels map[string]string)
IncrementCounter implements the MetricsCollector interface for OpenTelemetry-compatible counter metrics.
func (*MetricsCollectorSpy) IncrementCounterContext ¶
func (s *MetricsCollectorSpy) IncrementCounterContext(_ context.Context, metric string, labels map[string]string)
IncrementCounterContext implements the ContextualMetricsCollector interface. It delegates to the base IncrementCounter method for simplicity in testing.
func (*MetricsCollectorSpy) RecordDuration ¶
func (s *MetricsCollectorSpy) RecordDuration(metric string, duration time.Duration, labels map[string]string)
RecordDuration implements the MetricsCollector interface for OpenTelemetry-compatible duration metrics.
func (*MetricsCollectorSpy) RecordDurationContext ¶
func (s *MetricsCollectorSpy) RecordDurationContext(_ context.Context, metric string, duration time.Duration, labels map[string]string)
RecordDurationContext implements the ContextualMetricsCollector interface. It delegates to the base RecordDuration method for simplicity in testing.
func (*MetricsCollectorSpy) RecordValue ¶
func (s *MetricsCollectorSpy) RecordValue(metric string, value float64, labels map[string]string)
RecordValue implements the MetricsCollector interface for OpenTelemetry-compatible value/gauge metrics.
func (*MetricsCollectorSpy) RecordValueContext ¶
func (s *MetricsCollectorSpy) RecordValueContext(_ context.Context, metric string, value float64, labels map[string]string)
RecordValueContext implements the ContextualMetricsCollector interface. It delegates to the base RecordValue method for simplicity in testing.
func (*MetricsCollectorSpy) Reset ¶
func (s *MetricsCollectorSpy) Reset()
Reset clears all captured metric records.
func (*MetricsCollectorSpy) SupportsContextual ¶
func (s *MetricsCollectorSpy) SupportsContextual() bool
SupportsContextual returns whether this spy implements ContextualMetricsCollector. This is useful for tests that need to verify which code path was taken.
type SpanRecordMatcher ¶
type SpanRecordMatcher struct {
// contains filtered or unexported fields
}
SpanRecordMatcher provides a fluent interface for checking span records.
func (*SpanRecordMatcher) Assert ¶
func (m *SpanRecordMatcher) Assert() bool
Assert returns true if all conditions in the fluent chain were met.
func (*SpanRecordMatcher) WithEndAttribute ¶
func (m *SpanRecordMatcher) WithEndAttribute(key, value string) *SpanRecordMatcher
WithEndAttribute checks if the span record has the specified end attribute.
func (*SpanRecordMatcher) WithSpanAttribute ¶
func (m *SpanRecordMatcher) WithSpanAttribute(key, value string) *SpanRecordMatcher
WithSpanAttribute checks if the span context has the specified attribute.
func (*SpanRecordMatcher) WithStartAttribute ¶
func (m *SpanRecordMatcher) WithStartAttribute(key, value string) *SpanRecordMatcher
WithStartAttribute checks if the span record has the specified start attribute.
func (*SpanRecordMatcher) WithStatus ¶
func (m *SpanRecordMatcher) WithStatus(status string) *SpanRecordMatcher
WithStatus checks if the span record has the specified status.
type SpyContextualLogRecord ¶
type SpyContextualLogRecord struct { Level string Message string Args []any Context context.Context }
SpyContextualLogRecord represents a recorded contextual log call.
type SpyCounterRecord ¶
SpyCounterRecord represents a recorded counter increment call.
type SpyDurationRecord ¶
SpyDurationRecord represents a recorded duration metric call.
type SpyLogRecordMatcher ¶
type SpyLogRecordMatcher struct {
// contains filtered or unexported fields
}
SpyLogRecordMatcher provides a fluent interface for checking log record attributes.
func (*SpyLogRecordMatcher) Assert ¶
func (m *SpyLogRecordMatcher) Assert() bool
Assert returns true if all conditions in the fluent chain were met.
func (*SpyLogRecordMatcher) WithDurationMS ¶
func (m *SpyLogRecordMatcher) WithDurationMS() *SpyLogRecordMatcher
WithDurationMS checks if the log record has a duration_ms attribute with a non-negative value.
func (*SpyLogRecordMatcher) WithEventCount ¶
func (m *SpyLogRecordMatcher) WithEventCount() *SpyLogRecordMatcher
WithEventCount checks if the log record has an event_count attribute with a non-negative value.
func (*SpyLogRecordMatcher) WithExpectedEvents ¶
func (m *SpyLogRecordMatcher) WithExpectedEvents() *SpyLogRecordMatcher
WithExpectedEvents checks if the log record has an expected_events attribute with a non-negative value.
func (*SpyLogRecordMatcher) WithExpectedSequence ¶
func (m *SpyLogRecordMatcher) WithExpectedSequence() *SpyLogRecordMatcher
WithExpectedSequence checks if the log record has an expected_sequence attribute with a non-negative value.
func (*SpyLogRecordMatcher) WithRowsAffected ¶
func (m *SpyLogRecordMatcher) WithRowsAffected() *SpyLogRecordMatcher
WithRowsAffected checks if the log record has a rows_affected attribute with a non-negative value.
type SpySpanContext ¶
type SpySpanContext struct {
// contains filtered or unexported fields
}
SpySpanContext implements the SpySpanContext interface for testing tracing functionality.
func (*SpySpanContext) AddAttribute ¶
func (c *SpySpanContext) AddAttribute(key, value string)
AddAttribute implements the SpySpanContext interface for testing.
func (*SpySpanContext) GetAttributes ¶
func (c *SpySpanContext) GetAttributes() map[string]string
GetAttributes returns a copy of all attributes for testing.
func (*SpySpanContext) GetStatus ¶
func (c *SpySpanContext) GetStatus() string
GetStatus returns the current status of the span for testing.
func (*SpySpanContext) SetStatus ¶
func (c *SpySpanContext) SetStatus(status string)
SetStatus implements the SpySpanContext interface for testing.
type SpySpanRecord ¶
type SpySpanRecord struct { Name string StartAttributes map[string]string Status string EndAttributes map[string]string SpanContext *SpySpanContext }
SpySpanRecord represents a recorded span operation for testing.
type SpyValueRecord ¶
SpyValueRecord represents a recorded value metric call.
type TracingCollectorSpy ¶
type TracingCollectorSpy struct {
// contains filtered or unexported fields
}
TracingCollectorSpy is a TracingCollector implementation that captures tracing calls for testing. It implements the same interface pattern as MetricsCollectorSpy, making it suitable for testing EventStore tracing instrumentation that follows dependency-free tracing standards.
func NewTracingCollectorSpy ¶
func NewTracingCollectorSpy(recordCalls bool) *TracingCollectorSpy
NewTracingCollectorSpy creates a new TracingCollectorSpy for testing dependency-free tracing. Set recordCalls to true to capture all tracing calls for inspection in tests.
func (*TracingCollectorSpy) CountSpanRecordsForName ¶
func (s *TracingCollectorSpy) CountSpanRecordsForName(name string) int
CountSpanRecordsForName counts how many span records exist for a specific name.
func (*TracingCollectorSpy) FinishSpan ¶
func (s *TracingCollectorSpy) FinishSpan(spanCtx postgresengine.SpanContext, status string, attrs map[string]string)
FinishSpan implements the TracingCollector interface for testing.
func (*TracingCollectorSpy) GetSpanRecordCount ¶
func (s *TracingCollectorSpy) GetSpanRecordCount() int
GetSpanRecordCount returns the number of captured span records.
func (*TracingCollectorSpy) GetSpanRecords ¶
func (s *TracingCollectorSpy) GetSpanRecords() []SpySpanRecord
GetSpanRecords returns a copy of all captured span records.
func (*TracingCollectorSpy) HasSpanRecord ¶
func (s *TracingCollectorSpy) HasSpanRecord(name string) bool
HasSpanRecord checks if there's a span record with the specified name.
func (*TracingCollectorSpy) HasSpanRecordForName ¶
func (s *TracingCollectorSpy) HasSpanRecordForName(name string) *SpanRecordMatcher
HasSpanRecordForName starts a fluent chain to check a span record.
func (*TracingCollectorSpy) Reset ¶
func (s *TracingCollectorSpy) Reset()
Reset clears all captured span records.
func (*TracingCollectorSpy) StartSpan ¶
func (s *TracingCollectorSpy) StartSpan(ctx context.Context, name string, attrs map[string]string) (context.Context, postgresengine.SpanContext)
StartSpan implements the TracingCollector interface for testing.
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. |