Skip to content

fix: make weather fetcher injectable for stable unit tests - #64

Merged
robertoduessmann merged 2 commits into
masterfrom
fix/weather-test-stability
Oct 12, 2026
Merged

robertoduessmann merged 2 commits into
masterfrom
fix/weather-test-stability

Conversation

@robertoduessmann

Copy link
Copy Markdown
Owner

The failing CI job was caused by the weather handler performing a real external HTTP call during a test when the cache was empty.
This made the test depend on upstream network state and cache initialization, which produced flaky failures like “Expected request to be OK.”
This fix introduces an injectable WeatherFetcher so production still hits wttr.in, while tests can provide a stubbed response.
It keeps the cache behavior intact and makes the unit test deterministic.
Summary of the fix:

Add an injectable weather fetcher abstraction in controller/weather.go
Use the fetcher inside CurrentWeather
Keep cache hit/miss behavior unchanged
Make tests deterministic by injecting a mock response instead of hitting the network
This should resolve the failing job shown in:

https://github.com/robertoduessmann/weather-api/actions/runs/37654817287/job/112907127860

@robertoduessmann
robertoduessmann merged commit 37341f1 into master Oct 12, 2026
1 check passed
@robertoduessmann
robertoduessmann deleted the fix/weather-test-stability branch October 12, 2026 18:10
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.

1 participant