stdpgtest

package
v0.0.148 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 16 Imported by: 1

Documentation

Overview

Package stdpgtest provides testing against a postgresql database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute added in v0.0.26

func Execute(ctx context.Context, stdin io.Reader, dir, program string, args ...string) (string, error)

Execute shells out to a `program`, passing it STDIN (if given) and any specified arguments.

Examples:

Execute(ctx, nil, "echo", "hello", "world"
Execute(ctx, nil, "bash", "-c", "echo 'hello world'"

func NewPgxTestDB

func NewPgxTestDB(
	tb testing.TB,
	migrator pgtestdb.Migrator,
	setupConnStr string,
	testRole *pgtestdb.Role,
) *pgtestdb.Config

NewPgxTestDB will use the pgtestdb package to migrate, creates a isolated database and returns the connection string to that database..

func SetupPgxPool

func SetupPgxPool(ctx context.Context, tb testing.TB, snapshot []byte, connString string) *pgxpool.Pool

SetupPgxPool will init a isolated test database from a connection string and a snapshot sql file.

Types

type AtlasDirMigrator added in v0.0.24

type AtlasDirMigrator struct {
	MigrationsDirPath string
	AtlasEnv          string
	AtlasConfig       string
	Dir               string
	// contains filtered or unexported fields
}

AtlasDirMigrator is a pgtestdb.Migrator that uses the `atlas` CLI tool to perform migrations.

atlas migrate apply --url $DB --dir file://$migrationsDirPath

AtlasDirMigrator requires that it runs in an environment where the `atlas` CLI is in the $PATH. It shells out to that program to perform its migrations, as recommended by the Atlas maintainers.

AtlasDirMigrator does not perform any Verify() or Prepare() logic.

func NewAtlasDirMigrator added in v0.0.24

func NewAtlasDirMigrator(
	migrationsDirPath string,
	atlasEnv string,
	atlasConfig string,
	dir string,
	execute ExecuteFunc,
) *AtlasDirMigrator

NewAtlasDirMigrator returns a AtlasDirMigrator, which is a pgtestdb.Migrator that uses the `atlas` CLI tool to perform migrations.

atlas migrate apply --url $DB --dir file://$migrationsDirPath

func (*AtlasDirMigrator) Hash added in v0.0.24

func (m *AtlasDirMigrator) Hash() (string, error)

func (*AtlasDirMigrator) Migrate added in v0.0.24

func (m *AtlasDirMigrator) Migrate(
	ctx context.Context,
	_ *sql.DB,
	templateConf pgtestdb.Config,
) error

Migrate shells out to the `atlas` CLI program to migrate the template database.

atlas migrate apply --url $DB --dir file://$migrationsDirPath

type ExecuteFunc added in v0.0.26

type ExecuteFunc func(ctx context.Context, stdin io.Reader, dir, program string, args ...string) (string, error)

ExecuteFunc defines the signature for executing a command.

type SnapshotMigrator added in v0.0.24

type SnapshotMigrator[T interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}] []byte

SnapshotMigrator loads a migration from a postgres dump file.

func (SnapshotMigrator[T]) Hash added in v0.0.24

func (m SnapshotMigrator[T]) Hash() (string, error)

Hash implements the migrater interface.

func (SnapshotMigrator[T]) Migrate added in v0.0.24

func (m SnapshotMigrator[T]) Migrate(ctx context.Context, db T, _ pgtestdb.Config) error

Migrate performs the actual migration.

Jump to

Keyboard shortcuts

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