postgreswrapper

package
v1.3.1-beta Latest Latest
Warning

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

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

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanUp

func CleanUp(t testing.TB, wrapper Wrapper)

CleanUp truncates the events table to prepare for the next test.

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

func GetGreatestOccurredAtTimeFromDB(t testing.TB, wrapper Wrapper) time.Time

GetGreatestOccurredAtTimeFromDB retrieves the maximum occurred_at timestamp from the events table.

func GetLatestBookIDFromDB

func GetLatestBookIDFromDB(t testing.TB, wrapper Wrapper) uuid.UUID

GetLatestBookIDFromDB retrieves the most recent BookID from the events table payload.

func GuardThatThereAreEnoughFixtureEventsInStore

func GuardThatThereAreEnoughFixtureEventsInStore(wrapper Wrapper, expectedNumEvents int)

GuardThatThereAreEnoughFixtureEventsInStore verifies that the events table contains at least the expected number of events.

func OptimizeDBWhileBenchmarking

func OptimizeDBWhileBenchmarking(ctx context.Context, wrapper Wrapper) error

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) 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.

Jump to

Keyboard shortcuts

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