testutil

package
v1.20210104.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 11 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 MockTransitClient

type MockTransitClient struct {
	vault.Client
}

MockTransitClient skips interactions with the vault for encryption/decryption

func (MockTransitClient) Decrypt

func (m MockTransitClient) Decrypt(ctx context.Context, key string, context []byte, ciphertext string) ([]byte, error)

Decrypt just returns the input in the mock

func (MockTransitClient) Encrypt

func (m MockTransitClient) Encrypt(ctx context.Context, key string, context, data []byte) (string, error)

Encrypt just returns the input in the mock

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.

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