containers

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package containers provides test container utilities for integration testing. It wraps testcontainers-go to provide easy-to-use database containers for testing event stores and adapters.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidSchemaPrefix indicates the schema prefix contains invalid characters.
	ErrInvalidSchemaPrefix = errors.New("containers: schema prefix must contain only alphanumeric characters and underscores")

	// ErrInvalidPort indicates the port is not valid.
	ErrInvalidPort = errors.New("containers: port must be a valid number between 1 and 65535")

	// ErrEmptyPassword indicates the password is empty.
	ErrEmptyPassword = errors.New("containers: password cannot be empty")
)

Validation errors.

Functions

This section is empty.

Types

type FullStackTest

type FullStackTest struct {
	*IntegrationTest
}

FullStackTest provides complete end-to-end test infrastructure.

func NewFullStackTest

func NewFullStackTest(t *testing.T) *FullStackTest

NewFullStackTest creates a new full stack test environment.

func (*FullStackTest) SetupMinkSchema

func (fst *FullStackTest) SetupMinkSchema()

SetupMinkSchema creates the mink event store schema.

type IntegrationTest

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

IntegrationTest provides a complete integration test environment.

func NewIntegrationTest

func NewIntegrationTest(t *testing.T, opts ...IntegrationTestOption) *IntegrationTest

NewIntegrationTest creates a new integration test environment.

func (*IntegrationTest) ConnectionString

func (it *IntegrationTest) ConnectionString() string

ConnectionString returns the connection string with schema.

func (*IntegrationTest) Container

func (it *IntegrationTest) Container() *PostgresContainer

Container returns the PostgreSQL container.

func (*IntegrationTest) Context

func (it *IntegrationTest) Context() context.Context

Context returns the test context.

func (*IntegrationTest) DB

func (it *IntegrationTest) DB() *sql.DB

DB returns the database connection.

func (*IntegrationTest) Exec

func (it *IntegrationTest) Exec(query string, args ...interface{})

Exec executes a SQL statement.

func (*IntegrationTest) Query

func (it *IntegrationTest) Query(query string, args ...interface{}) *sql.Rows

Query executes a SQL query.

func (*IntegrationTest) Schema

func (it *IntegrationTest) Schema() string

Schema returns the test schema name.

type IntegrationTestOption

type IntegrationTestOption func(*integrationTestConfig)

IntegrationTestOption configures an integration test.

func WithSchemaPrefix

func WithSchemaPrefix(prefix string) IntegrationTestOption

WithSchemaPrefix sets the schema prefix.

func WithTimeout

func WithTimeout(timeout time.Duration) IntegrationTestOption

WithTimeout sets the test timeout.

type PostgresContainer

type PostgresContainer struct {
	Host     string
	Port     string
	Database string
	User     string
	Password string
	// contains filtered or unexported fields
}

PostgresContainer represents a PostgreSQL test container.

func StartPostgres

func StartPostgres(t *testing.T, opts ...PostgresOption) *PostgresContainer

StartPostgres starts a PostgreSQL test container. It uses the already running Docker container from docker-compose.test.yml in CI environments or can start a new container for local development.

For full testcontainers integration, install testcontainers-go: go get github.com/testcontainers/testcontainers-go

This implementation provides a lightweight alternative that works with the existing docker-compose.test.yml setup.

func (*PostgresContainer) ConnectionString

func (c *PostgresContainer) ConnectionString() string

ConnectionString returns the PostgreSQL connection string.

func (*PostgresContainer) CreateSchema

func (c *PostgresContainer) CreateSchema(ctx context.Context, db *sql.DB, prefix string) (string, error)

CreateSchema creates a unique test schema.

func (*PostgresContainer) DB

func (c *PostgresContainer) DB(ctx context.Context) (*sql.DB, error)

DB returns a database connection.

func (*PostgresContainer) DropSchema

func (c *PostgresContainer) DropSchema(ctx context.Context, db *sql.DB, schema string) error

DropSchema drops a test schema.

func (*PostgresContainer) MustDB

func (c *PostgresContainer) MustDB(ctx context.Context) *sql.DB

MustDB returns a database connection or panics.

type PostgresOption

type PostgresOption func(*postgresConfig)

PostgresOption configures a PostgreSQL container.

func WithPostgresDatabase

func WithPostgresDatabase(database string) PostgresOption

WithPostgresDatabase sets the database name.

func WithPostgresImage

func WithPostgresImage(image string) PostgresOption

WithPostgresImage sets the PostgreSQL Docker image.

func WithPostgresPassword

func WithPostgresPassword(password string) PostgresOption

WithPostgresPassword sets the database password.

func WithPostgresPort

func WithPostgresPort(port string) PostgresOption

WithPostgresPort sets the host port.

func WithPostgresUser

func WithPostgresUser(user string) PostgresOption

WithPostgresUser sets the database user.

Jump to

Keyboard shortcuts

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