Documentation
¶
Overview ¶
Package pgtesthelpers provides test utilities for PostgreSQL EventStore testing with multi-adapter support.
This package enables testing across different PostgreSQL drivers (pgx, sql.DB, sqlx.DB) through a unified Wrapper interface. Test adapter selection is controlled via the ADAPTER_TYPE environment variable, enabling comprehensive testing of all database implementations.
Adapter Types:
PGXPoolWrapper: wraps pgx.Pool for high-performance connection pooling SQLDBWrapper: wraps database/sql for standard library compatibility SQLXWrapper: wraps sqlx.DB for extended SQL functionality
Utility Functions:
CreateWrapperWithTestConfig: creates appropriate wrapper based on ADAPTER_TYPE env var CreateWrapperWithBenchmarkConfig: creates wrapper optimized for benchmarking CleanUp: removes all events from database for test isolation GetGreatestOccurredAtTimeFromDB: retrieves latest event timestamp for testing GetLatestBookIDFromDB: retrieves most recent book ID for benchmark continuity CleanUpBookEvents: removes events for specific book ID OptimizeDBWhileBenchmarking: runs PostgreSQL optimization during benchmarks
Environment Variables:
ADAPTER_TYPE: selects adapter (pgx.pool, sql.db, sqlx.db) TEST_PRIMARY_DSN: PostgreSQL primary instance DSN TEST_REPLICA_DSN: PostgreSQL replica instance DSN
Index ¶
- func CleanUp(t testing.TB, wrapper Wrapper)
- func CleanUpBookEvents(ctx context.Context, wrapper Wrapper, bookID uuid.UUID) (rowsAffected int64, err error)
- func GetGreatestOccurredAtTimeFromDB(t testing.TB, wrapper Wrapper) time.Time
- func GetLatestBookIDFromDB(t testing.TB, wrapper Wrapper) uuid.UUID
- func GuardThatThereAreEnoughFixtureEventsInStore(wrapper Wrapper, expectedNumEvents int)
- func OptimizeDBWhileBenchmarking(ctx context.Context, wrapper Wrapper) error
- func TryCreateEventStoreWithTableName(t testing.TB, options ...postgresengine.Option) error
- type PGXPoolWrapper
- type SQLDBWrapper
- type SQLXWrapper
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanUp ¶
CleanUp truncates both the events and snapshots tables to prepare for the next test. This is needed for tests that use the snapshot functionality.
func CleanUpBookEvents ¶
func CleanUpBookEvents(ctx context.Context, wrapper Wrapper, bookID uuid.UUID) (rowsAffected int64, err error)
CleanUpBookEvents deletes all events for a specific BookID and returns the number of rows affected.
func GetGreatestOccurredAtTimeFromDB ¶
GetGreatestOccurredAtTimeFromDB retrieves the maximum occurred_at timestamp from the events table.
func GetLatestBookIDFromDB ¶
GetLatestBookIDFromDB retrieves the most recent BookID from the events table payload.
func GuardThatThereAreEnoughFixtureEventsInStore ¶
GuardThatThereAreEnoughFixtureEventsInStore verifies that the events table contains at least the expected number of events.
func OptimizeDBWhileBenchmarking ¶
OptimizeDBWhileBenchmarking runs VACUUM ANALYZE on the events table to optimize performance during benchmarking.
func TryCreateEventStoreWithTableName ¶
func TryCreateEventStoreWithTableName(t testing.TB, options ...postgresengine.Option) error
TryCreateEventStoreWithTableName attempts to create an event store with custom options to test table name validation.
Types ¶
type PGXPoolWrapper ¶
type PGXPoolWrapper struct {
// contains filtered or unexported fields
}
PGXPoolWrapper wraps pgxpool-based testing.
func (*PGXPoolWrapper) Close ¶
func (e *PGXPoolWrapper) Close()
Close closes the underlying PGX pool connection.
func (*PGXPoolWrapper) GetEventStore ¶
func (e *PGXPoolWrapper) GetEventStore() *postgresengine.EventStore
GetEventStore returns the event store instance for the PGX pool wrapper.
type SQLDBWrapper ¶
type SQLDBWrapper struct {
// contains filtered or unexported fields
}
SQLDBWrapper wraps sql.DB-based testing.
func (*SQLDBWrapper) Close ¶
func (e *SQLDBWrapper) Close()
Close closes the underlying SQL DB connection.
func (*SQLDBWrapper) GetEventStore ¶
func (e *SQLDBWrapper) GetEventStore() *postgresengine.EventStore
GetEventStore returns the event store instance for the SQL DB wrapper.
type SQLXWrapper ¶
type SQLXWrapper struct {
// contains filtered or unexported fields
}
SQLXWrapper wraps sqlx.DB-based testing.
func (*SQLXWrapper) Close ¶
func (e *SQLXWrapper) Close()
Close closes the underlying SQLX DB connection.
func (*SQLXWrapper) GetEventStore ¶
func (e *SQLXWrapper) GetEventStore() *postgresengine.EventStore
GetEventStore returns the event store instance for the SQLX wrapper.
type Wrapper ¶
type Wrapper interface { GetEventStore() *postgresengine.EventStore Close() }
Wrapper interface to abstract over different engine types.
func CreateWrapperWithBenchmarkConfig ¶
func CreateWrapperWithBenchmarkConfig(t testing.TB, options ...postgresengine.Option) Wrapper
CreateWrapperWithBenchmarkConfig creates a database wrapper configured for benchmarking.
func CreateWrapperWithTestConfig ¶
func CreateWrapperWithTestConfig(t testing.TB, options ...postgresengine.Option) Wrapper
CreateWrapperWithTestConfig creates a database wrapper configured for testing with the specified options.