Skip to content

Stub remote HTTP requests in tests with mockito#67

Merged
frewsxcv merged 2 commits into
masterfrom
stub-test-requests
May 16, 2026
Merged

Stub remote HTTP requests in tests with mockito#67
frewsxcv merged 2 commits into
masterfrom
stub-test-requests

Conversation

@frewsxcv
Copy link
Copy Markdown
Member

@frewsxcv frewsxcv commented May 16, 2026

Summary

  • Adds mockito as a dev-dependency and rewrites the unit tests for the three providers (OpenCage, Nominatim, GeoAdmin) to serve canned JSON from a local mockito::Server instead of hitting the real APIs.
  • Adds Opencage::new_with_endpoint(api_key, endpoint) (mirroring the existing Openstreetmap::new_with_endpoint) so the tests can point the provider at the mock URL without exposing the previously-private endpoint field through some other shim.
  • Un-ignores the previously network-dependent GeoAdmin 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 access
  • cargo clippy --all-targets -- -D warnings — clean

frewsxcv added 2 commits May 16, 2026 02:26
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.
@frewsxcv frewsxcv marked this pull request as ready for review May 16, 2026 06:36
@frewsxcv frewsxcv merged commit 0c488c6 into master May 16, 2026
2 checks passed
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