testutils

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestDB

type TestDB struct {
	ConnPool  *pgxpool.Pool
	Container *tcpgres.PostgresContainer
}

TestDB holds the testcontainer and connection pool.

func NewTestDB

func NewTestDB(t *testing.T) *TestDB

NewTestDB creates a new test database with automatic cleanup. This is the preferred function for most tests.

Usage:

func TestMyRepo(t *testing.T) {
    db := testutils.NewTestDB(t)
    repo := myrepo.New(db.Pool())
    // ... test code
}

The container is automatically terminated when the test completes.

func StartTestDB

func StartTestDB(ctx context.Context) (*TestDB, error)

StartTestDB starts a PostgreSQL container using Testcontainers. This is a lower-level function for advanced use cases where you need manual control. For most tests, use NewTestDB instead.

func (*TestDB) Close

func (tdb *TestDB) Close(ctx context.Context) error

Close terminates the container and closes the pool.

func (*TestDB) Pool

func (tdb *TestDB) Pool() *pgxpool.Pool

Pool returns the connection pool (for convenience).

Jump to

Keyboard shortcuts

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