Stub remote HTTP requests in tests with mockito#67
Merged
Conversation
Replace network calls to OpenCage, Nominatim, and GeoAdmin with canned responses served by a local mockito server, so the unit tests no longer depend on internet connectivity or third-party service availability. Also adds an `Opencage::new_with_endpoint` constructor (mirroring `Openstreetmap::new_with_endpoint`) and unignores the previously network-dependent GeoAdmin `reverse_test`.
Inject a mockito server under # lines so the doctests no longer hit the live OpenCage API (whose demo key now returns 401). The hidden `new_with_endpoint` binding shadows the visible `Opencage::new` so the rendered docs still show the friendly constructor.
urschrei
approved these changes
May 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mockitoas a dev-dependency and rewrites the unit tests for the three providers (OpenCage, Nominatim, GeoAdmin) to serve canned JSON from a localmockito::Serverinstead of hitting the real APIs.Opencage::new_with_endpoint(api_key, endpoint)(mirroring the existingOpenstreetmap::new_with_endpoint) so the tests can point the provider at the mock URL without exposing the previously-privateendpointfield through some other shim.reverse_test(it was disabled in Add village to result object #45, the failure was a quirk of the live endpoint — irrelevant now that the response is stubbed).This removes the test suite's dependency on the OpenCage demo API key, the Nominatim usage policy / rate-limit, and the GeoAdmin endpoint being reachable from CI.
Test plan
cargo test --lib— all 20 tests pass with no network accesscargo clippy --all-targets -- -D warnings— clean