Documentation
¶
Overview ¶
Package postgreswrapper provides test utilities for abstracting over different PostgreSQL database adapters.
This package enables testing of the event store implementation across multiple database drivers (pgx, sql.DB, sqlx.DB) using a common Wrapper interface. The specific adapter type is determined by the ADAPTER_TYPE environment variable, allowing the same test suite to run against different database implementations.
Key features:
- Unified interface for different PostgreSQL adapters
- Test and benchmark configuration support
- Database cleanup and maintenance utilities
- Environment-based adapter selection for CI/CD flexibility
Usage:
// Create wrapper for testing wrapper := CreateWrapperWithTestConfig(t) defer wrapper.Close() // Clean up between tests CleanUp(t, wrapper) // Use the event store store := wrapper.GetEventStore()
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 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 ¶
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.