test: feature-gate PostgreSQL tests to remove external dependencies from cargo test#2558
Conversation
Co-authored-by: CommanderStorm <26258709+CommanderStorm@users.noreply.github.com>
Co-authored-by: CommanderStorm <26258709+CommanderStorm@users.noreply.github.com>
Co-authored-by: CommanderStorm <26258709+CommanderStorm@users.noreply.github.com>
cargo test
cargo testcargo test
There was a problem hiding this comment.
Pull request overview
This PR introduces a dedicated test-pg feature to ensure PostgreSQL-dependent tests don’t run under a plain cargo test, reducing contributor friction while keeping PG coverage available when explicitly enabled (and in CI).
Changes:
- Added a
test-pgfeature tomartinandmartin-coreand updated PG-related tests to gate ontest-pginstead ofpostgres. - Updated
justcommands and CI invocations to run the PostgreSQL test suite by explicitly enabling--features test-pg. - Documented the intended testing workflow in the development guide.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
martin/tests/utils.rs |
Gates PG-only helpers/imports behind test-pg to avoid compiling PG helpers in non-PG test runs. |
martin/tests/pg_table_source_test.rs |
Switches PG integration test gating from postgres to test-pg. |
martin/tests/pg_server_test.rs |
Switches PG integration test gating from postgres to test-pg. |
martin/tests/pg_function_source_test.rs |
Switches PG integration test gating from postgres to test-pg. |
martin/Cargo.toml |
Adds test-pg feature as a test-only gate (enables postgres). |
martin-core/src/tiles/postgres/pool.rs |
Gates container-based unit tests on test-pg to prevent DB/Docker requirements in default test runs. |
martin-core/Cargo.toml |
Adds test-pg feature as a test-only gate (enables postgres). |
justfile |
Updates commands that start PostgreSQL to run tests with --features test-pg. |
docs/src/development.md |
Adds a Testing section explaining default vs PG-enabled test runs. |
.github/workflows/ci.yml |
Ensures CI runs PG-dependent tests by explicitly enabling --features test-pg. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: CommanderStorm <26258709+CommanderStorm@users.noreply.github.com>
All changes from the review thread have been applied in commit 7ae0f09:
|
cargo testcargo test
Co-authored-by: CommanderStorm <26258709+CommanderStorm@users.noreply.github.com>
cargo testcargo test
justfile
Outdated
| # Run PostgreSQL-requiring tests only | ||
| test-pg: start | ||
| cargo test --features test-pg |
There was a problem hiding this comment.
@copilot
this will run all the tests AND the postgres requring ones.
Please make this run only the PG-specific ones.
Also make sure that the rest of the justfile does not have test-cargo "--all-targets" "--features" "test-pg" sprinkeled in.
There was a problem hiding this comment.
Fixed in b9e39b0 - just test-pg now runs only PostgreSQL-specific tests (the 3 integration test files + lib tests for martin and martin-core packages that contain PG-gated unit tests).
The other uses of test-cargo with test-pg in the justfile (test, test-legacy, test-ssl, coverage) are intentional - these recipes are designed to run the full test suite with PostgreSQL enabled, not just PG-specific tests.
Co-authored-by: CommanderStorm <26258709+CommanderStorm@users.noreply.github.com>
docs/src/development.md
Outdated
| just test # runs all tests | ||
| just test-pg # starts PostgreSQL and runs only PostgreSQL-requiring tests | ||
| ``` | ||
|
|
||
| The `test-pg` feature gates tests that require a live PostgreSQL connection. This allows developers to run most tests locally without setting up PostgreSQL, while CI and integration testing can enable these tests explicitly. |
There was a problem hiding this comment.
| just test # runs all tests | |
| just test-pg # starts PostgreSQL and runs only PostgreSQL-requiring tests | |
| ``` | |
| The `test-pg` feature gates tests that require a live PostgreSQL connection. This allows developers to run most tests locally without setting up PostgreSQL, while CI and integration testing can enable these tests explicitly. | |
| just test # runs all tests | |
| just test-pg # starts PostgreSQL and runs only PostgreSQL-requiring tests |
The test-pg feature gates tests that require a live PostgreSQL connection.
This allows developers to run most tests locally without setting up PostgreSQL, while CI and integration testing can enable these tests explicitly.
There was a problem hiding this comment.
Applied in 0d7ebcb - improved documentation formatting for better readability.
cargo testcargo test
- Remove start-pmtiles-server dependency from docker-up to prevent port 5412 conflict in CI - Apply documentation formatting suggestion for better readability Co-authored-by: CommanderStorm <26258709+CommanderStorm@users.noreply.github.com>
## 🤖 New release * `martin-tile-utils`: 0.6.10 -> 0.6.11 (✓ API compatible changes) * `mbtiles`: 0.15.2 -> 0.15.3 (✓ API compatible changes) * `martin-core`: 0.3.0 -> 0.3.1 (✓ API compatible changes) * `martin`: 1.3.1 -> 1.4.0 <details><summary><i><b>Changelog</b></i></summary><p> ## `mbtiles` <blockquote> ## [0.15.3](mbtiles-v0.15.2...mbtiles-v0.15.3) - 2026-03-14 ### Added - *(srv)* resolve some compression TODOS ([#2597](#2597)) ### Fixed - Accept any INT-containing type in MBTiles validation to be an integer ([#2560](#2560)) ### Other - rename the `webp.sql` fixture to `webp-no-primary.sql` ([#2564](#2564)) - More restrictive expects ([#2562](#2562)) </blockquote> ## `martin-core` <blockquote> ## [0.3.1](martin-core-v0.3.0...martin-core-v0.3.1) - 2026-03-14 ### Added - Add retry mechanism on locked/busy mbtiles files ([#2572](#2572)) ### Other - More restrictive expects ([#2562](#2562)) - feature-gate PostgreSQL tests to remove external dependencies from `cargo test` ([#2558](#2558)) </blockquote> ## `martin` <blockquote> ## [1.4.0](martin-v1.3.1...martin-v1.4.0) - 2026-03-14 ### Added - *(srv)* resolve some compression TODOS ([#2597](#2597)) - Migrate mdbooks to zensical ([#2576](#2576)) - *(martin-cp)* indicativ based progress bar ([#2495](#2495)) - Add retry mechanism on locked/busy mbtiles files ([#2572](#2572)) ### Fixed - *(ui)* render MLT tiles correctly in Tile Inspector ([#2601](#2601)) - redirect ignoring `--route-prefix` for .pbf tile requests ([#2599](#2599)) - restrict zooming and panning on data inspector ([#2574](#2574)) - Accept any INT-containing type in MBTiles validation to be an integer ([#2560](#2560)) ### Other - *(deps)* Bump the all-npm-version-updates group across 2 directories with 9 updates ([#2608](#2608)) - *(deps-dev)* Bump undici from 7.21.0 to 7.24.1 in /martin/martin-ui in the all-npm-security-updates group across 1 directory ([#2602](#2602)) - *(deps)* autoupdate pre-commit ([#2592](#2592)) - *(deps)* Bump the all-npm-version-updates group across 2 directories with 13 updates ([#2577](#2577)) - *(deps)* Bump the all-npm-security-updates group across 2 directories with 1 update ([#2575](#2575)) - *(deps)* autoupdate pre-commit ([#2567](#2567)) - rename the `webp.sql` fixture to `webp-no-primary.sql` ([#2564](#2564)) - more cfg magic instead of #[allow(unused_variables)] ([#2563](#2563)) - More restrictive expects ([#2562](#2562)) - feature-gate PostgreSQL tests to remove external dependencies from `cargo test` ([#2558](#2558)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Feature-gate PostgreSQL tests to simplify development
Goal: Make
cargo testpass without PostgreSQL running by creating a separatetest-pgfeature.Implementation Complete ✅
All PostgreSQL-requiring tests are now feature-gated behind the
test-pgfeature, which is NOT in the default feature set. This allows developers to runcargo testwithout setting up PostgreSQL, while CI and integration testing can explicitly enable these tests.Changes Summary:
1. Feature Definitions
test-pg = ["postgres"]featuretest-pg = ["postgres"]featurepostgresfeature but are NOT indefaultfeatures2. Test Files Updated
martin/tests/pg_function_source_test.rs- Changed from#![cfg(feature = "postgres")]to#![cfg(feature = "test-pg")]martin/tests/pg_server_test.rs- Changed from#![cfg(feature = "postgres")]to#![cfg(feature = "test-pg")]martin/tests/pg_table_source_test.rs- Changed from#![cfg(feature = "postgres")]to#![cfg(feature = "test-pg")]martin/tests/utils.rs- Updated PG helper functions to usetest-pgfeaturemartin-core/src/tiles/postgres/pool.rs- Changed test module from#[cfg(test)]to#[cfg(all(test, feature = "test-pg"))]martin/src/config/file/tiles/postgres/builder.rs- Changed test module from#[cfg(test)]to#[cfg(all(test, feature = "test-pg"))]to gate container-based tests3. Build System Updates
--features test-pgas separate arguments:test: Runs with"--all-targets" "--features" "test-pg"test-pg: Runs only PostgreSQL-specific tests (integration tests + lib tests with PG gates)test-legacy: Runs with"--all-targets" "--features" "test-pg"test-ssl: Runs with"--all-targets" "--features" "test-pg"coverage: Runs with--all-targets --features test-pgdocker-up: Fixed port conflict by removing unnecessarystart-pmtiles-serverdependencycargo testcommands for martin and martin-core packages to use--features test-pg4. Documentation
docs/src/development.mdwith comprehensive testing section explaining:cargo testjust testjust test-pgcargo test --features test-pg(requires DATABASE_URL env var)--features test-pgruns ALL tests (not just PG tests)Validation Results:
✅ Without test-pg feature (no PostgreSQL or Docker required):
cargo test --package martin --lib→ 53 tests pass (down from 55, confirming container tests are gated)cargo test --package martin-core --lib→ 34 tests passcargo test --workspace --lib→ All non-PG tests pass✅ With test-pg feature (requires PostgreSQL):
--features test-pg --no-runjust test(which starts PG) uses--features test-pgand runs ALL testsjust test-pgstarts PG and runs ONLY PostgreSQL-specific tests (integration + lib tests)--features test-pgwith PostgreSQL running✅ Non-PG tests unaffected:
✅ Justfile syntax validated:
test-pgrecipe now runs only PG-specific testsstart-pmtiles-serverdependency fromdocker-upImpact:
Before:
cargo testrequired PostgreSQL AND Docker to be running (for testcontainers)After:
cargo testworks without any external dependencies (no PG, no Docker)--features test-pgjust test-pgcommand runs ONLY PostgreSQL-specific tests (not all tests)Files Changed:
This implementation follows Rust best practices for feature-gating tests and maintains backward compatibility while significantly improving the development experience.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.