pgtest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunMain

func RunMain(ctx context.Context, m *testing.M, supervisor Supervisor) (code int)

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

func KeepDatabasesForFailed

func KeepDatabasesForFailed() Option

KeepDatabasesForFailed returns an option which prevents test databases from being dropped if the test they are used in fails. Such test databases will also not be re-used in future tests. By default test databases will be re-used regardless of whether or not tests fail, and will be automatically dropped when the supervisor is shutdown.

This option is primarily useful for debugging. Generally it is expected to combine this option with the '-run' flag when running tests in order to inspect the state of the database for a specific failing test.

func WithKeepDatabasesForFailed

func WithKeepDatabasesForFailed(v bool) Option

WithKeepDatabasesForFailed returns an option which controls whether or not to keep test databases if a test using them fails.

func WithResetOp

func WithResetOp(op ResetTestDBOp) Option

WithResetOp returns an option that specifies how to reset a test db in order to prepare it for future tests. By default this is set to DropAllTables().

type ResetTestDBOp

type ResetTestDBOp interface {
	// contains filtered or unexported methods
}

func DropAllTables

func DropAllTables() ResetTestDBOp

func DropAllTablesExcept

func DropAllTablesExcept(names ...string) ResetTestDBOp

func TruncateAllTables

func TruncateAllTables() ResetTestDBOp

func TruncateAllTablesExcept

func TruncateAllTablesExcept(names ...string) ResetTestDBOp

type Supervisor

type Supervisor interface {
	// GetTestDB returns a db for use in testing.
	GetTestDB(t testing.TB) TestDB

	// Shutdown shuts down the supervisor, dropping any test databases it
	// owns.
	Shutdown(ctx context.Context) error
}

A Supervisor is used to manage databases for use in a test suite.

func NewSupervisor

func NewSupervisor(ctx context.Context, opts ...Option) (Supervisor, error)

NewSupervisor returns a new supervisor, which maintains a pool of test databases for use in testing.

type TestDB

type TestDB interface {
	Name() string

	DataSourceName() string
	// contains filtered or unexported methods
}

func NewTestDB

func NewTestDB(t testing.TB) TestDB

NewTestDB returns a brand new TestDB that is dropped at the end of the test.

Directories

Path Synopsis
internal
pool
Package pool provides a generic resource pool.
Package pool provides a generic resource pool.

Jump to

Keyboard shortcuts

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