integrationstack

package
v1.2.0-rc3 Latest Latest
Warning

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

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

Documentation

Overview

Package integrationstack starts or stops the named Postgres and Alertmanager testcontainers used by integration tests. Host ports are assigned by the runtime (ephemeral); tests resolve them via PublishedTCPPort which queries podman/docker port. Redis is NOT part of the shared stack - each test suite creates its own ephemeral Redis via testdb.CreateTestRedis() to enable parallel test execution.

Index

Constants

View Source
const (
	PostgresContainerName     = "flightctl-integration-postgres"
	AlertmanagerContainerName = "flightctl-integration-alertmanager"
)

Container names for integration stack services. Note: Redis is NOT part of the shared stack - each test suite creates its own ephemeral Redis.

Variables

This section is empty.

Functions

func EnsureContainersOnly

func EnsureContainersOnly(ctx context.Context) error

EnsureContainersOnly starts containers without running migrations. Use this when you need to run migrations separately (e.g., from Makefile).

func EnsureRunning

func EnsureRunning(ctx context.Context) error

EnsureRunning starts Postgres and Alertmanager with reuse if they are not already running, then runs database migrations using the flightctl-db-migrate binary (same code path as production). If both containers are running and Postgres credentials match FLIGHTCTL_* env, skips container start. Migrations are run with a file lock to prevent parallel test suites from deadlocking on CREATE INDEX. If credentials differ from running containers, removes them so init SQL applies. Note: Redis is NOT started here - each test suite creates its own ephemeral Redis via testdb.CreateTestRedis().

func PublishedTCPPort

func PublishedTCPPort(containerName, containerTCPPort string) (host string, port uint, found bool)

PublishedTCPPort resolves the host-published TCP port for a named container.

func RunMigrations

func RunMigrations(ctx context.Context) error

RunMigrations sets up database users and runs migrations against the integration Postgres container. This matches the exact production flow used by Helm and Quadlet deployments: 1. Run setup_database_users.sql to create both migrator and app users with privileges 2. Run flightctl-db-migrate to apply schema migrations The process is idempotent - users are created only if they don't exist, and migrations use the schema_migrations table to skip already-applied migrations. No host dependencies required - psql runs inside the Postgres container via podman exec.

func RunMigrationsWithLock

func RunMigrationsWithLock(ctx context.Context) error

RunMigrationsWithLock runs migrations with a file lock to prevent parallel test suites from deadlocking when they all try to run CREATE INDEX statements simultaneously. The lock file is stored in /tmp and is automatically released when the process exits. A sentinel file tracks which database instance has been migrated to avoid redundant runs.

func Stop

func Stop(_ context.Context) error

Stop removes integration containers by name (best effort for each). Also removes the migrations sentinel so the next run will re-migrate.

Types

This section is empty.

Jump to

Keyboard shortcuts

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