dbtest

package
v0.0.0-...-a84dc14 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustGetPool

func MustGetPool(t *testing.T, schema []byte) *pgxpool.Pool

MustGetPool returns a shared *pgxpool.Pool backed by a single postgres testcontainer instance started once per test binary execution.

schema is the full DDL SQL applied after the container is ready. Pass your embed.FS content or a raw SQL string:

dbtest.MustGetPool(t, migrations.CurrentSchemaSQL)

Types

type Querier

type Querier[Q any] func(pgx.Tx) Q

Querier is a constructor function that creates a query executor from a transaction. Pass gen.New from your sqlc-generated package.

type Suite

type Suite[Q any] struct {
	suite.Suite

	Pool *pgxpool.Pool
	// contains filtered or unexported fields
}

Suite is a generic testify-suite for adapter integration tests.

Each test case gets its own transaction in SetupTest. TearDownTest rolls it back — no data leaks between tests, no TRUNCATE needed.

The adapter receives Q through ctxval.Or(ctx, a.g), so the transaction is picked up transparently without any changes to production code.

func NewSuite

func NewSuite[Q any](schema []byte, q Querier[Q]) Suite[Q]

NewSuite creates a Suite with the given querier constructor.

type productAdapterSuite struct {
    dbtest.Suite[*gen.Queries]
}

func (s *productAdapterSuite) SetupSuite() {
    s.Suite = dbtest.NewSuite(migrations.CurrentSchemaSQL, gen.New)
    s.Suite.SetupSuite()
}

func (*Suite[Q]) Ctx

func (s *Suite[Q]) Ctx() context.Context

Ctx returns the context with the current test transaction.

func (*Suite[Q]) Init

func (s *Suite[Q]) Init(schema []byte, q Querier[Q])

func (*Suite[Q]) SetupSuite

func (s *Suite[Q]) SetupSuite()

func (*Suite[Q]) SetupTest

func (s *Suite[Q]) SetupTest()

func (*Suite[Q]) TearDownTest

func (s *Suite[Q]) TearDownTest()

Jump to

Keyboard shortcuts

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