containers

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package containers starts real PostgreSQL, Redis and RabbitMQ instances in Docker for the integration tier, using testcontainers-go.

Tests that use it must be built with the "integration" tag, so an ordinary go test run never tries to reach a Docker daemon.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HealthCheck

type HealthCheck struct {
	ServiceName string
	CheckFunc   func(*TestContainers) error
	Timeout     time.Duration
	Interval    time.Duration
}

HealthCheck represents a health check for a container service

type TestContainerConfig

type TestContainerConfig struct {
	PostgresImage string
	RedisImage    string
	RabbitMQImage string
	StartTimeout  time.Duration
}

TestContainerConfig holds configuration for test containers

func DefaultTestContainerConfig

func DefaultTestContainerConfig() *TestContainerConfig

DefaultTestContainerConfig returns default configuration for test containers

type TestContainers

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

TestContainers manages Docker containers for testing

func NewTestContainers

func NewTestContainers(ctx context.Context) (*TestContainers, error)

NewTestContainers creates and starts test containers with the default images and startup timeout.

func NewTestContainersWithConfig

func NewTestContainersWithConfig(ctx context.Context, config *TestContainerConfig) (*TestContainers, error)

NewTestContainersWithConfig creates and starts test containers using the given images and startup timeout. A nil config, or any zero field within one, falls back to the defaults.

func (*TestContainers) CleanupDatabase

func (tc *TestContainers) CleanupDatabase() error

CleanupDatabase truncates all tables in the test database

func (*TestContainers) Close

func (tc *TestContainers) Close() error

Close stops and removes all test containers

func (*TestContainers) ExecInContainer

func (tc *TestContainers) ExecInContainer(containerName string, cmd []string) (string, error)

ExecInContainer executes a command in a specific container

func (*TestContainers) GetContainerLogs

func (tc *TestContainers) GetContainerLogs(containerName string) (string, error)

GetContainerLogs retrieves logs from a specific container

func (*TestContainers) GetPostgresConnectionString

func (tc *TestContainers) GetPostgresConnectionString() (string, error)

GetPostgresConnectionString returns a connection string for the test PostgreSQL container

func (*TestContainers) GetRabbitMQConnectionString

func (tc *TestContainers) GetRabbitMQConnectionString() (string, error)

GetRabbitMQConnectionString returns a connection string for the test RabbitMQ container

func (*TestContainers) GetRedisConnectionString

func (tc *TestContainers) GetRedisConnectionString() (string, error)

GetRedisConnectionString returns a connection string for the test Redis container

func (*TestContainers) LoadFixturesFromDirectory

func (tc *TestContainers) LoadFixturesFromDirectory(fixtureDir string) error

LoadFixturesFromDirectory loads all SQL fixture files from a directory

func (*TestContainers) LoadSQLFixture

func (tc *TestContainers) LoadSQLFixture(fixturePath string) error

LoadSQLFixture loads SQL fixture files into the test database

func (*TestContainers) OpenPostgres

func (tc *TestContainers) OpenPostgres() (*sql.DB, error)

OpenPostgres opens a connection pool to the test PostgreSQL container. The caller closes it.

func (*TestContainers) RunHealthChecks

func (tc *TestContainers) RunHealthChecks() error

RunHealthChecks runs health checks for all containers

func (*TestContainers) WaitForPostgres

func (tc *TestContainers) WaitForPostgres() error

WaitForPostgres waits for PostgreSQL to be ready for connections

func (*TestContainers) WaitForRabbitMQ

func (tc *TestContainers) WaitForRabbitMQ() error

WaitForRabbitMQ waits for RabbitMQ to be ready for connections

func (*TestContainers) WaitForRedis

func (tc *TestContainers) WaitForRedis() error

WaitForRedis waits for Redis to be ready for connections

Jump to

Keyboard shortcuts

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