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 ¶
- type HealthCheck
- type TestContainerConfig
- type TestContainers
- func (tc *TestContainers) CleanupDatabase() error
- func (tc *TestContainers) Close() error
- func (tc *TestContainers) ExecInContainer(containerName string, cmd []string) (string, error)
- func (tc *TestContainers) GetContainerLogs(containerName string) (string, error)
- func (tc *TestContainers) GetPostgresConnectionString() (string, error)
- func (tc *TestContainers) GetRabbitMQConnectionString() (string, error)
- func (tc *TestContainers) GetRedisConnectionString() (string, error)
- func (tc *TestContainers) LoadFixturesFromDirectory(fixtureDir string) error
- func (tc *TestContainers) LoadSQLFixture(fixturePath string) error
- func (tc *TestContainers) OpenPostgres() (*sql.DB, error)
- func (tc *TestContainers) RunHealthChecks() error
- func (tc *TestContainers) WaitForPostgres() error
- func (tc *TestContainers) WaitForRabbitMQ() error
- func (tc *TestContainers) WaitForRedis() error
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