Skip to content

Local Development

This guide covers setting up a local development environment for working with Spawn, including running PostgreSQL via Docker, executing tests, and inspecting test databases.

This project has a docker-compose file that you can use for integration testing:

Terminal window
docker compose up -d

Spawn has two categories of tests: unit tests, some of which use in-memory storage and require no external dependencies, and integration tests that require a running PostgreSQL instance.

Unit tests use in-memory storage via opendal and don’t need a database:

Terminal window
cargo test

Or to run all integration tests, which require the local database running

Terminal window
cargo test -- --ignored

Integration tests are marked with #[ignore] so they don’t run during a normal cargo test. They require a running PostgreSQL instance.

With Docker (recommended for local development):

Terminal window
docker compose up -d
cargo test --test integration_postgres -- --ignored

With a direct PostgreSQL configuration:

Set environment variables to point at your PostgreSQL instance:

Terminal window
SPAWN_TEST_PSQL_HOST=localhost \
SPAWN_TEST_PSQL_PORT=5432 \
SPAWN_TEST_PSQL_USER=spawn \
PGPASSWORD=spawn \
cargo test --test integration_postgres -- --ignored

Running a specific integration test:

Terminal window
cargo test --test integration_postgres test_migration_is_idempotent -- --ignored --nocapture

Each integration test creates its own unique database, so tests can run without interference. Databases are automatically dropped when each test completes.

By default, test databases are cleaned up after each test. To preserve them for manual inspection, set SPAWN_TEST_KEEP_DB:

Terminal window
SPAWN_TEST_KEEP_DB=1 cargo test --test integration_postgres test_migration_creates_table -- --ignored --nocapture

This prints the database name and connection instructions so you can connect and inspect the results with psql.