Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Running Tests

Tests require PostgreSQL and Redis running. Use Docker Compose to start them:

docker-compose up -d postgres redis

Run all tests

From modules/mycelium-api-gateway/:

cargo test

With logs visible:

RUST_LOG=debug cargo test -- --nocapture

Filtering tests

cargo test auth              # all tests with "auth" in the name
cargo test -p mycelium-base  # specific workspace package
cargo test --workspace       # every package

Pre-commit checks

These must all pass before merging:

cargo fmt --all -- --check
cargo build --workspace
cargo test --workspace --all

Coverage (optional)

cargo install cargo-tarpaulin
cargo tarpaulin --out Html

Test database setup

psql postgres://postgres:postgres@localhost:5432/postgres \
  -c "CREATE DATABASE mycelium_test;"

Set the env var before running tests that need a separate database:

export TEST_DATABASE_URL="postgres://postgres:postgres@localhost:5432/mycelium_test"

Troubleshooting

Tests hang — run with --test-threads=1 to serialize them.

Flaky tests — run the failing test in isolation: cargo test <test_name> -- --nocapture.

Port conflict — stop any running myc-api process or Docker containers on the same ports.