Skip to content

Add unit tests for modules/lunarphase (0% → 93.7% coverage) - #2159

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

Add unit tests for modules/lunarphase (0% → 93.7% coverage)#2159
Seanstoppable wants to merge 1 commit into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-lunarphase-test-coverage

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

Adds comprehensive unit tests for the modules/lunarphase package, bringing statement coverage from 0% to 93.7%.

Changes

  • widget.go: Added an unexported baseURL field to Widget (defaults to "https://wttr.in") to allow HTTP endpoint injection in tests. No behavior change for production code.
  • widget_test.go: 683 lines of table-driven tests using net/http/httptest.

Test Coverage

Function Coverage
NewWidget 100%
Refresh 100%
RefreshTitle 100%
lunarPhase 80%
NextDay / PrevDay / NextWeek / PrevWeek 100%
Today 100%
setDay 100%
DisableWidget 100%
NewSettingsFromYAML 100%
ConfigText 100%
initializeKeyboardControls 100%
OpenMoonPhase 0% (opens browser)

What's Tested

  • Settings parsing with defaults and custom values
  • Date format constants (dateFormat, phaseFormat)
  • HTTP request construction (URL path, query params, language headers)
  • Response parsing with ANSI → tview color conversion
  • Error paths: connection refused, timeout, empty body
  • Result caching (same day not re-fetched)
  • Day navigation with month/year boundary rollover
  • Widget initialization and disable/enable toggle
  • Refresh behavior in both enabled and disabled states

Add comprehensive table-driven tests covering:
- Settings parsing (defaults and custom values)
- Date format constants (dateFormat, phaseFormat)
- HTTP request construction (URL path, query params, headers)
- Language header propagation
- Response parsing with ANSI color conversion
- Error paths: connection refused, timeout, empty body
- Result caching behavior (same day not re-fetched)
- Navigation: NextDay, PrevDay, NextWeek, PrevWeek, Today
- Boundary cases: month/year rollovers
- Widget initialization and custom timeout
- Disable/Enable toggle
- Refresh behavior when disabled vs enabled

Uses net/http/httptest to mock the wttr.in API. Adds an
unexported baseURL field to Widget for test injection
(defaults to production URL, no behavior change).
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