Skip to content

Add unit tests for modules/updown (0% -> 71% coverage) - #2164

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

Add unit tests for modules/updown (0% -> 71% coverage)#2164
Seanstoppable wants to merge 1 commit into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-updown-test-coverage

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

Adds comprehensive unit tests for the modules/updown package, bringing test coverage from 0% to 71.1%.

Changes

  • widget_test.go - Table-driven tests covering: timeSincePing, makeURL, filterChecks, contentFrom, content, getExistingChecks (success, token filtering, 401/500 responses, invalid JSON, empty responses, connection errors via httptest), JSON parsing of Check struct fields
  • helpers_test.go - Test helper to override API base URL for httptest
  • widget.go - Changed apiURLBase from const to var to allow test server injection

Coverage

Function Coverage
content 100%
contentFrom 100%
timeSincePing 100%
makeURL 100%
filterChecks 100%
getExistingChecks 90.9%
Total 71.1%

- Table-driven tests for timeSincePing, makeURL, filterChecks, contentFrom, content
- httptest-based tests for getExistingChecks: success, token filtering,
  non-200 responses, invalid JSON, empty responses, connection errors
- Convert apiURLBase from const to var to enable test server injection
- Test JSON parsing of Check struct fields
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