testutil

package
v0.0.0-...-bc49051 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

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

FailureCodes

Variables

This section is empty.

Functions

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 DropTestDatabase

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

DropTestDatabase drops a database.

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 OptWithDefaultDB

func OptWithDefaultDB(opts ...db.Option) Option

OptWithDefaultDB runs a test suite with a dedicated database connection.

type Suite

type Suite struct {
	M      *testing.M
	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 calls os.Exit(...) with the exit code.

func (Suite) RunCode

func (s Suite) RunCode() (code int)

RunCode runs the suite and returns an exit code.

It is used by `.Run()`, which will os.Exit(...) this 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