dbpgxtest

package
v0.0.0-...-42ca271 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupTables

func CleanupTables(ctx context.Context, tx pgx.Tx, tables ...string)

CleanupTables truncates tables. Should be called with all tables at once to reset the database while respecting referential integrity constraints.

func DbTester

func DbTester(
	t *testing.T,
	txnlSubtest TransactionalSubtest,
	connStr string,
	cleanupTables func(db dbpgx.Db, ctx context.Context),
)

DbTester runs txnlSubtest with a clean database.

func RunTestPairs

func RunTestPairs(db dbpgx.Db, ctx context.Context, t *testing.T, name string, testPairs []TestPair)

RunTestPairs executes a list of TestPair.

Types

type DafSubtest

type DafSubtest func(
	ctx context.Context,
	tx pgx.Tx,
	t *testing.T,
)

DafSubtest is the type of a function that implements a DAF subtest that is to be delimited by a transaction.

type TestPair

type TestPair struct {
	Name string
	Func TransactionalSubtest
}

TestPair pairs a TransactionalSubtest with a name for execution in a test suite.

type TransactionalSubtest

type TransactionalSubtest func(
	db dbpgx.Db,
	ctx context.Context,
	t *testing.T,
)

TransactionalSubtest is the tyype of a function that implements a DAF subtest that is already delimited by one or more transactions.

func Parallel

func Parallel(txnlSubtest TransactionalSubtest) TransactionalSubtest

Parallel returns a decorated TransactionalSubtest that calls t.Parallel() just before executing txnlSubtest.

func TestWithTransaction

func TestWithTransaction(
	f DafSubtest,
) TransactionalSubtest

TestWithTransaction is a convenience wrapper to transform a DafSubtest into a TransactionalSubtest.

Jump to

Keyboard shortcuts

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