This document describes how to test PostgreSQL Docker images against the pg_regress test suite.
The test-docker-image.sh script builds a Docker image from one of the project's Dockerfiles and runs the existing nix/tests/ test suite against it. This validates that Docker images work correctly before deployment.
# Test PostgreSQL 17 image
./test-docker-image.sh Dockerfile-17
# Test PostgreSQL 15 image
./test-docker-image.sh Dockerfile-15
# Test OrioleDB 17 image
./test-docker-image.sh Dockerfile-orioledb-17- Docker
- Nix (provides psql and pg_regress from the flake)
Usage: ./test-docker-image.sh [OPTIONS] DOCKERFILE
Test a PostgreSQL Docker image against the pg_regress test suite.
Arguments:
DOCKERFILE The Dockerfile to build and test (e.g., Dockerfile-17)
Options:
-h, --help Show this help message
--no-build Skip building the image (use existing)
--keep Keep the container running after tests (for debugging)
# Build and test
./test-docker-image.sh Dockerfile-17
# Test without rebuilding (faster iteration)
./test-docker-image.sh --no-build Dockerfile-17
# Keep container running for debugging
./test-docker-image.sh --keep Dockerfile-17
# Then connect with:
# psql -h localhost -p 5435 -U supabase_admin postgres- Build - Builds Docker image from the specified Dockerfile
- Start - Runs container with PostgreSQL exposed on a test port
- Wait - Waits for PostgreSQL to be ready (pg_isready)
- HTTP Mock - Starts the HTTP mock server inside the container for
httpextension tests - Setup - Runs
prime.sqlto enable all extensions, createstest_configtable - Patch - Copies test files to temp dir, patches expected outputs for Docker-specific differences
- Test - Runs pg_regress with version-filtered test files
- Compare - Checks output against patched expected files
- Report - Shows pass/fail, prints diffs on failure
- Cleanup - Removes container (unless
--keep)
| Dockerfile | Version | Test Port | Test Filter | Tests |
|---|---|---|---|---|
| Dockerfile-15 | 15 | 5436 | z_15_*.sql + common |
53 |
| Dockerfile-17 | 17 | 5435 | z_17_*.sql + common |
49 |
| Dockerfile-orioledb-17 | orioledb-17 | 5437 | z_orioledb-17_*.sql + common |
47 |
Tests in nix/tests/sql/ are filtered by PostgreSQL version:
- Files without
z_prefix run for all versions - Files starting with
z_15_run only for PostgreSQL 15 - Files starting with
z_17_run only for PostgreSQL 17 - Files starting with
z_orioledb-17_run only for OrioleDB 17
jobs:
test-docker:
runs-on: ubuntu-latest
strategy:
matrix:
dockerfile:
- Dockerfile-15
- Dockerfile-17
- Dockerfile-orioledb-17
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
- name: Test Docker image
run: ./test-docker-image.sh ${{ matrix.dockerfile }}When tests fail, the script outputs regression.diffs showing the differences between expected and actual output.
To investigate further:
# Run with --keep to preserve container
./test-docker-image.sh --keep Dockerfile-17
# Connect to the running database
psql -h localhost -p 5435 -U supabase_admin postgres
# Run individual test manually
psql -h localhost -p 5435 -U supabase_admin postgres -f nix/tests/sql/pgroonga.sqlThis script complements nix flake check which tests the Nix-built PostgreSQL packages directly. The Docker tests validate that:
- Docker image builds correctly
- Extensions are properly installed in the container
- Configuration files are correctly applied
- The containerized PostgreSQL behaves the same as the Nix-built version
The script automatically patches expected outputs at runtime to handle Docker-specific differences:
| Difference | Affected Tests | Cause |
|---|---|---|
$user → \$user in search_path |
pgmq, vault, roles | Docker image configuration escapes $ in search_path |
These patches are applied to a temporary copy of the test files - the original files are never modified.
For tests that produce different output under OrioleDB (due to the orioledb extension being loaded or different storage behavior), create OrioleDB-specific versions:
nix/tests/sql/z_orioledb-17_<testname>.sql- OrioleDB version of the testnix/tests/expected/z_orioledb-17_<testname>.out- Expected output for OrioleDB
When an OrioleDB variant exists, the common test is automatically skipped for OrioleDB runs. This approach is used by both the Docker test script and Nix flake checks.
- Add SQL file to
nix/tests/sql/ - Add expected output to
nix/tests/expected/ - For version-specific tests, prefix with
z_15_,z_17_, orz_orioledb-17_
See existing tests for examples.