Add unit tests for arpansagovau module (0% → 84% coverage) - #2156
Open
Seanstoppable wants to merge 1 commit into
Open
Add unit tests for arpansagovau module (0% → 84% coverage)#2156Seanstoppable wants to merge 1 commit into
Seanstoppable wants to merge 1 commit into
Conversation
- Add client_test.go: XML parsing tests, httptest-based tests for getLocationData and apiRequest (success, server error, invalid XML, connection refused, city not found) - Add widget_test.go: table-driven tests for formatLocationData covering all UV levels (LOW/MODERATE/HIGH/VERY HIGH/EXTREME), boundary values, empty name, and non-ok status - Add settings_test.go: NewSettingsFromYAML with various configs - Extract apiURL variable to enable httptest injection - Fix defer resp.Body.Close() bug in apiRequest (was closing body before caller could read it)
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
Adds comprehensive unit tests for
modules/weatherservices/arpansagovauusingnet/http/httptestto mock the ARPANSA UV data API.Changes
New test files:
client_test.go— XML parsing tests + httptest-based integration tests forgetLocationDataandapiRequest(success, server error, invalid XML, connection refused, city not found)widget_test.go— table-driven tests forformatLocationDatacovering all 5 UV index levels (LOW/MODERATE/HIGH/VERY HIGH/EXTREME), boundary values, empty name, and non-ok statussettings_test.go—NewSettingsFromYAMLwith various config scenariosProduction fix:
apiURLpackage variable to enable httptest injectionapiRequestuseddefer resp.Body.Close()before the caller could read the bodyCoverage
The remaining ~16% is in
NewWidget,content(), andRefresh()which requiretview.Applicationinfrastructure and are impractical to unit test without broader widget test harness changes.