Skip to content

Add unit tests for modules/healthchecks (0% → 98.6% coverage) - #2167

Open
Seanstoppable wants to merge 2 commits into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-healthchecks-test-coverage
Open

Add unit tests for modules/healthchecks (0% → 98.6% coverage)#2167
Seanstoppable wants to merge 2 commits into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-healthchecks-test-coverage

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

Adds comprehensive unit tests for modules/healthchecks, bringing test coverage from 0% to 98.6%.

Test Coverage

Function Coverage
NewWidget 100%
Refresh 100%
Render 100%
content 100%
contentFrom 100%
timeSincePing 100%
makeURL 100%
getExistingChecks 95%
NewSettingsFromYAML 100%
ConfigText 100%
initializeKeyboardControls 100%

The remaining 1.4% is a defer resp.Body.Close() statement in getExistingChecks.

What's tested

  • URL construction (makeURL): with/without tags, invalid URLs
  • Status formatting (contentFrom): all status color mappings (green/red/lightgray/yellow)
  • API integration (getExistingChecks): uses net/http/httptest to mock the Healthchecks.io API
    • Successful response parsing (all JSON fields)
    • Tag query parameter forwarding
    • HTTP error codes (401, 403, 500)
    • Invalid JSON handling
    • Connection errors, invalid base URL
  • Widget lifecycle: NewWidget, Refresh (disabled + active), Render
  • Settings: NewSettingsFromYAML with various configs, ConfigText
  • Display logic (content): error display, nil checks, up/total counting in title

All tests are table-driven where applicable.

- Table-driven tests for makeURL, timeSincePing, contentFrom
- httptest-based tests for getExistingChecks: success, tags, error codes, invalid JSON, connection errors
- Tests for content() method: error display, nil checks, check counting
- Full JSON field parsing verification
- Add tests for NewWidget, Refresh (disabled + active), Render
- Add tests for NewSettingsFromYAML with various configs
- Add test for ConfigText
- Use buffered redrawChan and tview.Application for full widget tests
- All functions at 100% except getExistingChecks defer (95%)
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