dbinitiator

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 26 Imported by: 1

README

testdb

Documentation

Overview

Implements tooling to setup a Spanner database configured for running integration tests against.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSpannerInstance

func NewSpannerInstance(ctx context.Context, projectID, instanceID string, opts ...option.ClientOption) error

NewSpannerInstance creates a spanner instance. This is intended for use with a spanner emulator.

func PostgresConnStr added in v0.1.2

func PostgresConnStr(username, password, host, port, database string) string

Types

type PostgresContainer added in v0.1.2

type PostgresContainer struct {
	testcontainers.Container
	// contains filtered or unexported fields
}

PostgresContainer represents a docker container running a postgres instance.

func NewPostgresContainer added in v0.1.2

func NewPostgresContainer(ctx context.Context, imageVersion string) (*PostgresContainer, error)

NewPostgresContainer returns a new PostgresContainer ready to use with postgres.

func (*PostgresContainer) Close added in v0.1.2

func (pc *PostgresContainer) Close()

Close closes all connections to the postgres instance

func (*PostgresContainer) CreateDatabase added in v0.1.2

func (pc *PostgresContainer) CreateDatabase(ctx context.Context, dbName string) (*PostgresDatabase, error)

CreateDatabase creates a new database with the given name and returns a connection to it.

type PostgresDatabase added in v0.1.2

type PostgresDatabase struct {
	*pgxpool.Pool
	// contains filtered or unexported fields
}

PostgresDatabase represents a postgres database created and ready for migrations

func NewPostgresDatabase added in v0.1.2

func NewPostgresDatabase(ctx context.Context, database, schema, connStr string) (*PostgresDatabase, error)

NewPostgresDatabase represents a new postgres database

func (*PostgresDatabase) Close added in v0.1.2

func (db *PostgresDatabase) Close()

Close closes the database connection

func (*PostgresDatabase) MigrateDown added in v0.1.2

func (db *PostgresDatabase) MigrateDown(sourceURL string) error

MigrateDown will migrate all the way down

func (*PostgresDatabase) MigrateUp added in v0.1.2

func (db *PostgresDatabase) MigrateUp(sourceURL ...string) error

MigrateUp will migrate all the way up, applying all up migrations from all sourceURL's

func (*PostgresDatabase) Schema added in v0.1.2

func (db *PostgresDatabase) Schema() string

Schema returns the default schema

type SpannerContainer

type SpannerContainer struct {
	testcontainers.Container
	// contains filtered or unexported fields
}

SpannerContainer represents a docker container running a spanner instance.

func NewSpannerContainer

func NewSpannerContainer(ctx context.Context, imageVersion string) (*SpannerContainer, error)

NewSpannerContainer returns a initialized SpannerContainer ready to run to create databases for unit tests

func (*SpannerContainer) Close

func (sc *SpannerContainer) Close() error

Close cleans up open resouces

func (*SpannerContainer) CreateDatabase added in v0.2.0

func (sc *SpannerContainer) CreateDatabase(ctx context.Context, dbName string) (*SpannerDB, error)

CreateDatabase creates a database with dbName. Each test should create their own database for testing

type SpannerDB

type SpannerDB struct {
	*spanner.Client
	// contains filtered or unexported fields
}

SpannerDB represents a database created and ready for migrations

func NewSpannerDatabase

func NewSpannerDatabase(ctx context.Context, projectID, instanceID, dbName string, opts ...option.ClientOption) (*SpannerDB, error)

NewSpannerDatabase will create a spanner database

func (*SpannerDB) Close

func (db *SpannerDB) Close() error

func (*SpannerDB) DropDatabase

func (db *SpannerDB) DropDatabase(ctx context.Context) error

func (*SpannerDB) MigrateDown

func (db *SpannerDB) MigrateDown(sourceURL string) error

MigrateDown will migrate all the way down

func (*SpannerDB) MigrateUp

func (db *SpannerDB) MigrateUp(sourceURL ...string) error

MigrateUp will migrate all the way up, applying all up migrations from all sourceURL's

Jump to

Keyboard shortcuts

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