testutil

package
v1.20210818.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SuiteFailureTests  = 1
	SuiteFailureBefore = 2
	SuiteFailureAfter  = 3
)

FailureCodes

Variables

This section is empty.

Functions

func BeginAll

func BeginAll() ([]*sql.Tx, error)

BeginAll begins a transaction in each of the underlying connections. If an error is raised by *any* of the connections, t

func CreateTestDatabase

func CreateTestDatabase(ctx context.Context, opts ...db.Option) (*db.Connection, error)

CreateTestDatabase creates a randomized test database.

func DefaultDB

func DefaultDB() *db.Connection

DefaultDB returns a default database connection for tests.

func DefaultDBs

func DefaultDBs() []*db.Connection

DefaultDBs returns a default set database connections for tests.

func DropTestDatabase

func DropTestDatabase(ctx context.Context, conn *db.Connection, opts ...db.Option) error

DropTestDatabase drops a database.

func RollbackAll

func RollbackAll(txs ...*sql.Tx) error

RollbackAll calls `Rollback` on a set of transactions.

Types

type Option

type Option func(*Suite)

Option is a mutator for a test suite.

func OptAfter

func OptAfter(steps ...SuiteAction) Option

OptAfter appends after run actions.

func OptBefore

func OptBefore(steps ...SuiteAction) Option

OptBefore appends before run actions.

func OptLog

func OptLog(log logger.Log) Option

OptLog sets the suite logger.

func OptWithDefaultDB

func OptWithDefaultDB() Option

OptWithDefaultDB runs a test suite with a dedicated database connection.

func OptWithDefaultDBs

func OptWithDefaultDBs(count int) Option

OptWithDefaultDBs runs a test suite with a count of database connections. Note: this type of connection pool is used in rare circumstances for performance reasons; you probably want to use `OptWithDefaultDB` for your tests.

func OptWithStatementLabelRequired added in v1.20210603.3

func OptWithStatementLabelRequired() Option

OptWithStatementLabelRequired adds a defaultdb interceptor that enforces that statement labels must be present on all statements.

type Suite

type Suite struct {
	M      *testing.M
	Log    logger.Log
	Before []SuiteAction
	After  []SuiteAction
}

Suite is a set of before and after actions for a given package tests.

func New

func New(m *testing.M, opts ...Option) *Suite

New returns a new test suite.

func (Suite) Run

func (s Suite) Run()

Run runs tests and returns the exit code.

type SuiteAction

type SuiteAction func(context.Context) error

SuiteAction is a step that can be run either before or after package tests.

Jump to

Keyboard shortcuts

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