buntest

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSQLiteDB

func NewSQLiteDB(tb TestingTB) *bun.DB

NewSQLiteDB initializes a new instance of *bun.DB, which is ready for use (all required migrations are applied). Data is stored in memory (https://www.sqlite.org/inmemorydb.html).

Types

type Fixture

type Fixture struct {
	// contains filtered or unexported fields
}

func NewFixture

func NewFixture(bunDB *bun.DB) *Fixture

func (*Fixture) Load

func (f *Fixture) Load(tb TestingTB, ctx context.Context, fsys fs.FS, names ...string)

type Postgres

type Postgres struct {
	// contains filtered or unexported fields
}

func NewPostgres

func NewPostgres(pool *dockertest.Pool, opts ...PostgresOption) (*Postgres, error)

NewPostgres constructs a new Postgres resource. If the env variable 'TESTS_POSTGRES_CONNECTION_STRING' is set, this function doesn't run a new Docker container and uses the value of this variable as a connection string, otherwise this function runs a new PostgresSQL database in a Docker container. This function is intended for use in TestMain.

func (*Postgres) Close

func (p *Postgres) Close() error

func (*Postgres) NewDB

func (p *Postgres) NewDB(tb TestingTB) *bun.DB

NewDB initializes a new instance of *bun.DB, which is ready for use (all required migrations are applied). This method guarantees data separation through PostgresSQL schemas (https://www.postgresql.org/docs/current/ddl-schemas.html) and it is safe to call postgres.NewDB multiple times.

It fails if Postgres hasn't been properly initialized (via NewPostgres).

type PostgresOption

type PostgresOption func(cfg *postgresConfig)

func WithPostgresImage

func WithPostgresImage(image string) PostgresOption

func WithPostgresTTL

func WithPostgresTTL(ttlSeconds uint) PostgresOption

type TestingTB

type TestingTB interface {
	Helper()
	Errorf(format string, args ...any)
	FailNow()
	Cleanup(f func())
}

TestingTB is a subset of the API provided by both *testing.T and *testing.B.

Jump to

Keyboard shortcuts

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