Skip to content

test: feature-gate PostgreSQL tests to remove external dependencies from cargo test#2558

Merged
CommanderStorm merged 24 commits intomainfrom
copilot/feature-gate-postgresql-tests
Feb 12, 2026
Merged

test: feature-gate PostgreSQL tests to remove external dependencies from cargo test#2558
CommanderStorm merged 24 commits intomainfrom
copilot/feature-gate-postgresql-tests

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

Feature-gate PostgreSQL tests to simplify development

Goal: Make cargo test pass without PostgreSQL running by creating a separate test-pg feature.

Implementation Complete ✅

All PostgreSQL-requiring tests are now feature-gated behind the test-pg feature, which is NOT in the default feature set. This allows developers to run cargo test without setting up PostgreSQL, while CI and integration testing can explicitly enable these tests.

Changes Summary:

1. Feature Definitions

  • martin/Cargo.toml: Added test-pg = ["postgres"] feature
  • martin-core/Cargo.toml: Added test-pg = ["postgres"] feature
  • Both features enable the postgres feature but are NOT in default features

2. 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 use test-pg feature
  • martin-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 tests

3. Build System Updates

  • justfile: Updated commands to properly pass --features test-pg as 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-pg
    • docker-up: Fixed port conflict by removing unnecessary start-pmtiles-server dependency
  • CI (.github/workflows/ci.yml): Updated all cargo test commands for martin and martin-core packages to use --features test-pg

4. Documentation

  • Updated docs/src/development.md with comprehensive testing section explaining:
    • How to run tests without PostgreSQL: cargo test
    • How to run ALL tests with PostgreSQL: just test
    • How to run ONLY PostgreSQL tests: just test-pg
    • How to run tests with PostgreSQL using cargo: cargo test --features test-pg (requires DATABASE_URL env var)
    • Clarified that --features test-pg runs ALL tests (not just PG tests)
    • Package-specific testing examples
    • Improved formatting for better readability

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 pass
  • cargo test --workspace --lib → All non-PG tests pass
  • PG integration tests show "running 0 tests" (correctly skipped)
  • Container-based builder tests are skipped

With test-pg feature (requires PostgreSQL):

  • Tests compile successfully with --features test-pg --no-run
  • just test (which starts PG) uses --features test-pg and runs ALL tests
  • just test-pg starts PG and runs ONLY PostgreSQL-specific tests (integration + lib tests)
  • CI explicitly enables --features test-pg with PostgreSQL running

Non-PG tests unaffected:

  • MBTiles tests continue to work
  • PMTiles tests continue to work
  • Styles, sprites, fonts tests continue to work

Justfile syntax validated:

  • Arguments properly passed as separate strings to avoid shell escaping issues
  • test-pg recipe now runs only PG-specific tests
  • Fixed port conflict in CI by removing start-pmtiles-server dependency from docker-up

Impact:

Before:

  • cargo test required PostgreSQL AND Docker to be running (for testcontainers)
  • Developers needed to set up Docker and start PG before testing
  • No simple command to run just PostgreSQL tests
  • CI had port conflicts due to unnecessary dependencies

After:

  • cargo test works without any external dependencies (no PG, no Docker)
  • Developers can test most of the codebase immediately
  • CI maintains full test coverage with explicit --features test-pg
  • just test-pg command runs ONLY PostgreSQL-specific tests (not all tests)
  • CI port conflicts resolved

Files Changed:

  • 2 Cargo.toml files (feature definitions)
  • 6 test files (feature gates, including builder.rs)
  • 1 justfile (test commands with proper arg passing + test-pg recipe + fixed docker-up)
  • 1 CI workflow (explicit feature flags)
  • 1 documentation file (clarified testing requirements + improved formatting)

This implementation follows Rust best practices for feature-gating tests and maintains backward compatibility while significantly improving the development experience.

Original prompt

This section details on the original issue you should resolve

<issue_title>Make all PG-requiring tests feature-gated</issue_title>
<issue_description>We need to simplify our testing process, and that means that cargo test should pass without any external dependencies, i.e. without requiring PG to be running, or some env var to be set.

I think PostgreSQL tests are the only complex ones, so lets mark them all as requiring some test-pg feature (name?). Note that cargo test --all-features should still include the postgreSQL tests, and thus require some connection string to be set. This will be done by CI, but will make development simpler.</issue_description>

Comments on the Issue (you are @copilot in this section)

@todtb I was running full tests (including w/ pg) locally while working on the srid 4326 issue. I can take a look here.

If I understand correctly we'll just need to identify different tests w/ dependencies (pg, aws, etc), add a feature tag outside the default set, and modify the justfile commands accordingly? Then as for CI/CD, I'd imagine I'll need help setting up any required envvars</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 11, 2026 16:05
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>
Copilot AI changed the title [WIP] Make PostgreSQL requiring tests feature-gated Feature-gate PostgreSQL tests to remove external dependencies from cargo test Feb 11, 2026
Copilot AI requested a review from CommanderStorm February 11, 2026 16:28
@CommanderStorm CommanderStorm changed the title Feature-gate PostgreSQL tests to remove external dependencies from cargo test tests: feature-gate PostgreSQL tests to remove external dependencies from cargo test Feb 11, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-pg feature to martin and martin-core and updated PG-related tests to gate on test-pg instead of postgres.
  • Updated just commands 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>
@CommanderStorm
Copy link
Member

@copilot apply changes based on the comments in this thread

Co-authored-by: CommanderStorm <26258709+CommanderStorm@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 11, 2026

@copilot apply changes based on the comments in this thread

All changes from the review thread have been applied in commit 7ae0f09:

  • Fixed justfile argument passing (separate quoted strings)
  • Clarified documentation about DATABASE_URL requirement
  • Gated container-based tests in builder.rs with test-pg feature

@CommanderStorm CommanderStorm changed the title tests: feature-gate PostgreSQL tests to remove external dependencies from cargo test test: feature-gate PostgreSQL tests to remove external dependencies from cargo test Feb 11, 2026
Co-authored-by: CommanderStorm <26258709+CommanderStorm@users.noreply.github.com>
Copilot AI changed the title test: feature-gate PostgreSQL tests to remove external dependencies from cargo test tests: feature-gate PostgreSQL tests to remove external dependencies from cargo test Feb 11, 2026
Copilot AI requested a review from CommanderStorm February 11, 2026 17:21
justfile Outdated
Comment on lines +388 to +390
# Run PostgreSQL-requiring tests only
test-pg: start
cargo test --features test-pg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Member

@nyurik nyurik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable

Comment on lines +155 to +159
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 0d7ebcb - improved documentation formatting for better readability.

@CommanderStorm CommanderStorm marked this pull request as ready for review February 11, 2026 18:01
@CommanderStorm CommanderStorm enabled auto-merge (squash) February 11, 2026 18:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

@CommanderStorm CommanderStorm changed the title tests: feature-gate PostgreSQL tests to remove external dependencies from cargo test test: feature-gate PostgreSQL tests to remove external dependencies from cargo test Feb 11, 2026
@CommanderStorm CommanderStorm marked this pull request as draft February 12, 2026 04:57
auto-merge was automatically disabled February 12, 2026 04:57

Pull request was converted to draft

- 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>
@CommanderStorm CommanderStorm marked this pull request as ready for review February 12, 2026 05:11
@CommanderStorm CommanderStorm enabled auto-merge (squash) February 12, 2026 05:11
@CommanderStorm CommanderStorm merged commit 844c95a into main Feb 12, 2026
39 of 40 checks passed
@CommanderStorm CommanderStorm deleted the copilot/feature-gate-postgresql-tests branch February 12, 2026 05:50
@CommanderStorm CommanderStorm mentioned this pull request Feb 12, 2026
CommanderStorm added a commit that referenced this pull request Mar 15, 2026
## 🤖 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make all PG-requiring tests feature-gated

4 participants