eltest

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: MIT Imports: 14 Imported by: 0

README

eltest - Elephant test

Support library for writing elephant tests.

Takes care of setting up Postgres and Minio containers for intergration tests. See tests for usage, and don't miss setting up TestMain() in your own service:

func TestMain(m *testing.M) {
	code := m.Run()

	err := eltest.PurgeBackingServices()
	if err != nil {
		log.Printf("failed to purge backing services: %v", err)
	}

	os.Exit(code)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bootstrap

func Bootstrap[T BackingService](id string, srv T) (T, error)

func Must

func Must(t T, err error, actionFormat string, a ...any)

func PurgeBackingServices

func PurgeBackingServices() error

Types

type BackingService

type BackingService interface {
	SetUp(pool *dockertest.Pool) error
	Purge(pool *dockertest.Pool) error
}

type Minio

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

func NewMinio

func NewMinio(t T) *Minio

func (*Minio) Client

func (m *Minio) Client() (*minio.Client, error)

func (*Minio) CreateBucket

func (m *Minio) CreateBucket(t T, ctx context.Context, prefix string) string

CreateBucket with the given prefix and a suffix based on the test name.

func (*Minio) Environment

func (m *Minio) Environment() MinioEnvironment

func (*Minio) Purge

func (m *Minio) Purge(pool *dockertest.Pool) error

func (*Minio) SetUp

func (m *Minio) SetUp(pool *dockertest.Pool) error

type MinioEnvironment

type MinioEnvironment struct {
	Endpoint string
	ID       string
	Secret   string
}

type PGEnvironment

type PGEnvironment struct {
	PostgresURI string
	// contains filtered or unexported fields
}

func (*PGEnvironment) Migrator

func (env *PGEnvironment) Migrator(t T, ctx context.Context, conn *pgx.Conn) *migrate.Migrator

type Postgres

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

func NewPostgres

func NewPostgres(t T) *Postgres

func (*Postgres) Database

func (pg *Postgres) Database(
	t T,
	migrations fs.FS,
	runMigrations bool,
) PGEnvironment

func (*Postgres) Purge

func (pg *Postgres) Purge(pool *dockertest.Pool) error

func (*Postgres) SetUp

func (pg *Postgres) SetUp(pool *dockertest.Pool) error

type T

type T interface {
	Name() string
	Helper()
	Fatalf(format string, args ...any)
}

Jump to

Keyboard shortcuts

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