Skip to content

Add unit tests for arpansagovau module (0% → 84% coverage) - #2156

Open
Seanstoppable wants to merge 1 commit into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-arpansagovau-test-coverage
Open

Add unit tests for arpansagovau module (0% → 84% coverage)#2156
Seanstoppable wants to merge 1 commit into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-arpansagovau-test-coverage

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

Adds comprehensive unit tests for modules/weatherservices/arpansagovau using net/http/httptest to mock the ARPANSA UV data API.

Changes

New test files:

  • client_test.go — XML parsing tests + httptest-based integration tests for getLocationData and apiRequest (success, server error, invalid XML, connection refused, city not found)
  • widget_test.go — table-driven tests for formatLocationData covering all 5 UV index levels (LOW/MODERATE/HIGH/VERY HIGH/EXTREME), boundary values, empty name, and non-ok status
  • settings_test.goNewSettingsFromYAML with various config scenarios

Production fix:

  • Extracted apiURL package variable to enable httptest injection
  • Fixed bug where apiRequest used defer resp.Body.Close() before the caller could read the body

Coverage

Before After
0% 84%

The remaining ~16% is in NewWidget, content(), and Refresh() which require tview.Application infrastructure and are impractical to unit test without broader widget test harness changes.

- 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant