Skip to content

test: adopt rstest for parameterized tests (#19) - #21

Closed
remdalm wants to merge 3 commits into
silvermine:masterfrom
remdalm:feat/rstest
Closed

remdalm wants to merge 3 commits into
silvermine:masterfrom
remdalm:feat/rstest

Conversation

@remdalm

@remdalm remdalm commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

No description provided.

- Stream a chunked body so the mid-stream body limit check runs
- Pin the early Content-Length rejection by its advertised size, replacing a
  test that passed even without the early check
- Assert lower bounds in the backoff tests, and that jitter varies
- Check that InFlightRequests::default() and new() start empty
- Use a forbidden header to show merge_headers passes defaults through, and
  assert ForbiddenHeader in the per-request rejection test
- Revoke a runtime domain mid-retry to test allowlist revalidation
- Make the security-error retry test fail during an attempt; its old error
  was raised before the retry loop, so it could never have been retried
- Cover Error::Request codes and the retryable timeout and connect branch
- Check the full message in every error serialization test
- Pass a real String in test_body_from_string
reqwest's Attempt::previous() includes the original request URL, so the
`previous().len() >= max_redirects` check stopped one redirect early:
max_redirects(1) followed none and the default of 10 followed 9. Use `>`,
as reqwest's own Policy::limited does, and add a test for a chain that is
exactly max_redirects long.

The hop-limit tests now assert the exact status and, where the status cannot
tell where the chain stopped, the final URL. Accepting any 3xx let them pass
with the bug.
@remdalm
remdalm requested a review from a team October 20, 2026 20:53
@remdalm
remdalm marked this pull request as draft October 20, 2026 20:53
Tests that ran the same check on several inputs, in one function or in sibling
functions, are now #[rstest] tables with one named case per input. Each input
passes or fails on its own and can be run by name. Scenarios, multi-aspect
checks and stateful sequences stay plain #[test] functions.

Every input is still checked. The few that were checked twice (the 408 status,
POST and PATCH, the first backoff attempt) now appear once, with their
rationale kept as a comment on the case. The tables hold 246 cases in 45
functions.

Two changes go beyond moving tests into tables:
- test_validate_header_name_blocks asserts ForbiddenHeader with the lowercased
  name instead of just is_err(). This covers test_validate_header_name_blocks_host,
  which becomes the host_lower case, and
  test_validate_header_name_error_contains_lowercased_name, which is removed.
- The three pack_ipc_response body tests become one table that compares the
  bytes after the metadata with the input body. Their different status codes
  and headers did not matter to what they tested.

`npm run rust:lint` now also runs scripts/lint-rstest-attributes.cjs, the same
script as in the sibling plugins. On rstest 0.28 a test attribute above the
last #[case] silently drops cases and clippy does not warn; the script rejects
that order.

rstest 0.28.0 is a dev-dependency with default features off, as
tauri-plugin-connectivity does.
@remdalm
remdalm marked this pull request as ready for review October 20, 2026 21:57
@@ -0,0 +1,139 @@
/**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟠 P2 — Remove the rstest lint script and the rust:lint:rstest step from this PR

The PR adds scripts/lint-rstest-attributes.cjs to rust:lint, but the tauri-plugin-connectivity adoption of rstest added no such script.

Details

The commit body says the script is "the same script as in the sibling plugins". No sibling has it on its default branch. The connectivity rust:lint script is still cargo lint-clippy && cargo lint-fmt. The script exists only in this PR, tauri-plugin-sqlite#73 and tauri-plugin-media-parser#32.

The script has no tests and cannot be imported, because it calls main() on load and exports nothing. A later regex change can turn the check off without a signal. Its documented default roots are crates src, but this repo has no crates/. Run with no arguments, it fails with ENOENT: scandir 'crates'.

Removing it removes the guard against dropped cases. rstest generates only case_1 when #[test] is above the cases. Today all 45 #[rstest] functions in this PR use a safe order.

Delete scripts/lint-rstest-attributes.cjs. In package.json, set rust:lint back to cargo lint-clippy && cargo lint-fmt and remove rust:lint:rstest. Remove the lint-script paragraph from the commit body. If the team wants this guard later, add it to shared tooling so that every plugin gets it.

Comment added by AI model Claude

Comment thread Cargo.toml Resolved
@remdalm remdalm closed this Oct 24, 2026
@remdalm
remdalm deleted the feat/rstest branch October 24, 2026 09:02
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.

2 participants