Skip to content

fix: make postgres tests hygienic for persistent databases#6

Merged
ceejbot merged 1 commit into
latestfrom
fix/postgres-test-hygiene
Mar 29, 2026
Merged

fix: make postgres tests hygienic for persistent databases#6
ceejbot merged 1 commit into
latestfrom
fix/postgres-test-hygiene

Conversation

@ceejbot

@ceejbot ceejbot commented Mar 29, 2026

Copy link
Copy Markdown
Owner

Summary

Postgres integration tests previously truncated the entire secrets and audit_events tables in their setup, making them non-hygienic when run against a persistent local database. Tests would fail if run a second time without cleaning the DB, or if run concurrently.

Changes

  • No more table truncation. test_store() and test_audit_log() no longer run DELETE FROM <table>.
  • Per-test cleanup. Each test deletes only the specific rows it created, both before (handle interrupted prior runs) and after.
  • Unique names. Each test uses distinct, prefixed names (pg-roundtrip, pg-list-a, test-alice, etc.) to avoid collisions.
  • Flexible assertions. list_returns_metadata uses contains() instead of exact count, since other data may exist in the table.
  • Descriptive assertion messages throughout.

Test plan

  • cargo clippy --manifest-path crates/zerolease-store-postgres/Cargo.toml --all-targets — clean
  • cargo test --workspace — all pass
  • CI green

Each test now cleans up only the data it created instead of truncating
the entire table. Tests use unique, prefixed names and clean up both
before and after to handle interrupted prior runs.

Store tests:
- Removed DELETE FROM secrets in test_store()
- Added cleanup() helper that deletes by specific names
- list test uses contains() assertions instead of exact count
- Unique names per test (pg-roundtrip, pg-list-a, etc.)

Audit tests:
- Removed DELETE FROM audit_events in test_audit_log()
- Added cleanup_agent/cleanup_secret/cleanup_lease helpers
- Unique agent names (test-alice, test-bob) to avoid collisions
- Each test cleans before and after
@ceejbot ceejbot merged commit 11eff2a into latest Mar 29, 2026
3 checks passed
@ceejbot ceejbot deleted the fix/postgres-test-hygiene branch March 29, 2026 02:30
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.

1 participant