test(api-db,health): consolidate duplicated CRUD and IP-candidate tests#2714
test(api-db,health): consolidate duplicated CRUD and IP-candidate tests#2714chet wants to merge 1 commit into
Conversation
|
@coderabbitai PTAL, thanks! |
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (9)
💤 Files with no reviewable changes (2)
🚧 Files skipped from review as they are similar to previous changes (7)
Summary by CodeRabbitRelease Notes
Note: This release focuses on test coverage and reliability improvements only; no user-facing behavior changes. WalkthroughThis PR introduces a shared ChangesExpected-host delete test refactor
Test consolidation and cleanup
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/api-db/src/route_servers.rs`:
- Around line 424-427: The assertion in the replace test is using a generic
is_err() check that will pass for any error, not just duplicate constraint
violations. Replace the generic assert!(result.is_err()) call with a more
specific assertion that validates the error is specifically a duplicate or
UNIQUE-constraint violation error. Check the result for the corresponding
DatabaseError variant that represents constraint violations (such as a
constraint error type or similar) to ensure the test truly pins the
duplicate-rejection behavior rather than masking unrelated failures.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 77068414-d3f1-4af8-83d5-acd54852d47a
📒 Files selected for processing (9)
crates/api-db/src/expected_machine/tests.rscrates/api-db/src/expected_power_shelf/tests.rscrates/api-db/src/expected_rack/tests.rscrates/api-db/src/expected_switch/tests.rscrates/api-db/src/ip_allocator.rscrates/api-db/src/route_servers.rscrates/api-db/src/test_support/expected_host.rscrates/api-db/src/test_support/mod.rscrates/health/src/sharding.rs
💤 Files with no reviewable changes (2)
- crates/health/src/sharding.rs
- crates/api-db/src/expected_rack/tests.rs
The `expected_{machine,switch,power_shelf}` suites each repeated an identical
delete-then-confirm-absent body. That flow now lives once in a `test_support`
helper that takes each entity's `delete_by_mac` / `find_by_bmc_mac_address` as
async closures; every entity keeps its own `#[sqlx_test]` (one pool per test) and
its own lookup / duplicate / update tests, since those have distinct
constructors. `ip_allocator`'s three IPv4-candidate tests become one `check_cases`
table, and `expected_rack`'s pure insert-then-read-back round-trips -- which
asserted no transformation -- are removed.
Two weak tests are repaired rather than just dropped where a real contract
exists. `route_servers`'s `test_sync_with_duplicate_addresses_in_input` used to
accept either `Ok` or `Err`, so it could not fail; it now pins the actual
behavior -- `replace` hands its input to a single batched INSERT, so a duplicate
address trips the `address inet NOT NULL UNIQUE` constraint and the whole call is
rejected. `health`'s `should_monitor_key` "consistency" test asserted
`f(x) == f(x)` and is removed outright.
No production change. Verified against Postgres -- the changed api-db modules
(55 tests) and `health` sharding (4) pass.
Signed-off-by: Chet Nichols III <chetn@nvidia.com>
🔍 Container Scan Summary
Per-CVE detail lives in the per-service |
Wave 1 of the carbide-test-support integration (#2692).
api-db: the threeexpected_{machine,switch,power_shelf}suites shared an identical delete-then-confirm-absent body -- it now lives once in atest_supporthelper that each entity's#[sqlx_test]calls with its owndelete_by_mac/find_by_bmc_mac_address(per-entity lookup/duplicate/update tests stay, since constructors differ). Theip_allocatorIPv4-candidate trio becomes onecheck_casestable;expected_rack's pure insert-read-back round-trips are removed.Two weak tests are repaired, not just dropped:
route_servers'stest_sync_with_duplicate_addresses_in_inputaccepted eitherOkorErr(couldn't fail) and now pins the real contract -- a duplicate address trips theUNIQUEconstraint, soreplacerejects it.health'sshould_monitor_keytest assertedf(x) == f(x)and is removed.No production change. Verified against Postgres (
cargo test: changed api-db modules 55, health sharding 4).Addresses #2698.