testdb

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CleanupFunc

type CleanupFunc func(ctx context.Context, pool *pgxpool.Pool) error

type DBWithPool

type DBWithPool struct {
	// contains filtered or unexported fields
}

DBWithPool is a wrapper for a puddle resource for a test database. The database is made available via a preconfigured pgxpool.Pool.

func (*DBWithPool) Pool

func (db *DBWithPool) Pool() *pgxpool.Pool

Pool returns the underlying pgxpool.Pool for the test database.

func (*DBWithPool) Release

func (db *DBWithPool) Release()

Release releases the DBWithPool back to the Manager. This should be called when the test is finished with the database.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages a pool of test databases up to a max size. Each DB keeps a pgxpool.Pool which is available when one is acquired from the Manager. Databases can optionally be prepared with a PrepareFunc before being added into the pool, and cleaned up with a CleanupFunc before being returned to the pool for reuse.

This setup makes it trivial to run fully isolated tests in parallel.

func NewManager

func NewManager(config *pgxpool.Config, maxPoolSize int32, prepare PrepareFunc, cleanup CleanupFunc) (*Manager, error)

NewManager creates a new Manager with the given databaseURL, maxPoolSize, and optional prepare/cleanup funcs.

func (*Manager) Acquire

func (m *Manager) Acquire(ctx context.Context) (*DBWithPool, error)

Acquire returns a DBWithPool which contains a pgxpool.Pool. The DBWithPool must be released after use.

func (*Manager) Close

func (m *Manager) Close()

Close closes the Manager and all of its databases + pools. It blocks until all those underlying resources are unused and closed.

type PrepareFunc

type PrepareFunc func(ctx context.Context, pool *pgxpool.Pool) error

Jump to

Keyboard shortcuts

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