Skip to content

Add unit tests for prettyweather module (0% → 75.9% coverage) - #2153

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

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

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

Adds unit tests for modules/weatherservices/prettyweather using net/http/httptest to mock the wttr.in API.

Changes

  • widget.go: Extract hardcoded base URL into a baseURL field on the Widget struct for testability (no behavioral change — defaults to https://wttr.in/)
  • widget_test.go: Comprehensive table-driven tests covering:
    • Successful response formatting (trimming, multiline, empty body)
    • Request URL construction with city/unit/view parameters
    • HTTP header verification (Accept-Language, User-Agent)
    • Error paths: invalid URL, connection refused, hijacked connections
    • ANSI escape code processing through ASCIItoTviewColors
    • NewSettingsFromYAML with default values and custom overrides

Coverage

coverage: 75.9% of statements

The remaining ~24% is in NewWidget() and Refresh() which require a full tview.Application and widget rendering infrastructure.

- Add httptest-based tests for prettyWeather() method
- Test request URL construction with city/unit/view parameters
- Test Accept-Language and User-Agent headers
- Test error paths: invalid URL, connection refused, hijacked connection
- Test ANSI code processing via ASCIItoTviewColors
- Test NewSettingsFromYAML with defaults and custom values
- Refactor widget to use baseURL field for testability

Table-driven tests throughout.
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