Skip to content

test(rattler_upload): convert tests to mockito#2277

Open
benmoss wants to merge 8 commits intoconda:mainfrom
benmoss:mockito-tests
Open

test(rattler_upload): convert tests to mockito#2277
benmoss wants to merge 8 commits intoconda:mainfrom
benmoss:mockito-tests

Conversation

@benmoss
Copy link
Copy Markdown
Contributor

@benmoss benmoss commented Mar 23, 2026

Description

Convert all rattler_upload tests from custom axum-based mock servers to mockito for more declarative, readable, and maintainable HTTP mocking, then reduce boilerplate with rstest parameterization.

  • Convert all 21 tests across anaconda, cloudsmith, prefix, quetz, and artifactory upload targets
  • Use specific path matching (exact strings and regex) instead of Matcher::Any
  • Assert all mocks are called to verify expected HTTP requests are made
  • Remove axum dev-dependency, add rstest (already a workspace dep)
  • Use rstest #[case] to collapse repeated status-code variant tests (e.g. 3 quetz tests → 1 parameterized test)
  • Extract shared setup helpers to eliminate duplicated server/client/package construction
  • Net result: -165 lines vs the original axum-based tests

Fixes #2262

How Has This Been Tested?

All 21 rattler_upload tests pass:

pixi run -- cargo nextest run -p rattler_upload

Formatting and lints verified with pixi run cargo-fmt and pixi run cargo-clippy.

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.

Tools: Claude Code (Claude Opus 4.6)

Checklist:

  • I have performed a self-review of my own code
  • I have added sufficient tests to cover my changes.

benmoss and others added 8 commits March 23, 2026 09:48
Replace hand-rolled axum test servers with mockito for the two simple
cloudsmith tests (api_key_header, request_upload_failure) and the
mod.rs cloudsmith_upload_success test. Leave the multipart upload test
using axum where it's a better fit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Convert quetz, artifactory, anaconda, and prefix tests from axum to
mockito. Remove the now-unused start_test_server helper from test_utils.
The only remaining axum usage is the multipart cloudsmith upload test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ckito tests

Replace Matcher::Any with specific path patterns for Quetz and Artifactory
tests, and add mock assertions to auth failure/conflict tests to verify
the expected HTTP calls are actually made.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…e axum dev-dep

Replace the axum-based test server in test_cloudsmith_multipart_upload_flow
with mockito mocks, using expect_at_least(1) for chunk count verification.
This removes the axum dev-dependency from rattler_upload.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ation

Add rstest for #[case] parameterization and shared setup helpers,
collapsing repeated status-code variant tests and eliminating
duplicated server/client/package construction (-326/+119 lines).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Avoid hitting real prefix.dev when running in CI where
detect_ci_provider() would return Some(GitHub).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@benmoss benmoss marked this pull request as ready for review March 23, 2026 16:12
@baszalmstra baszalmstra requested a review from wolfv March 24, 2026 12:29
@baszalmstra
Copy link
Copy Markdown
Collaborator

Looks good from my perspective but maybe @wolfv can take a closer look at the details.

let package = ExtractedPackage::from_package_file(&package_path).unwrap();

let mock = server
.mock("POST", mockito::Matcher::Regex(r"^/stage/.*".to_string()))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

worth pointing out that some of these are slightly more "relaxed" assertions by not asserting on the exact URL now but I don't think this was the important aspect of these tests

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.

Explore refactoring rattler_upload tests to use mockito

2 participants