Skip to content

Add unit tests for modules/uptimekuma (0% → 99% coverage) - #2162

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

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

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

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

Tests Added

widget_test.go

  • TestParseURL — table-driven tests for URL parsing (valid URLs, edge cases, error paths)
  • TestFetchStatusData_* — httptest-based tests for status page fetching (success, non-200, invalid JSON, connection errors)
  • TestFetchHeartbeatData_* — httptest-based tests for heartbeat fetching (success, non-200, invalid JSON, connection errors)
  • TestContent_* — display rendering tests (error state, loading, all-up, mixed statuses, incidents with valid/unparsable dates, empty data, out-of-range status values)
  • TestNewWidget — widget construction
  • TestRefresh_FullIntegration_* — end-to-end Refresh tests (success, invalid URL, status fetch error, heartbeat fetch error)
  • TestConfigText — verifies help text generation

settings_test.go

  • TestNewSettingsFromYAML — settings construction with URL
  • TestNewSettingsFromYAML_EmptyURL — settings with missing URL
  • TestDefaultConstants — verifies default values

helpers_test.go

  • Test helpers (makeTestCommon, makeTestWidget) for creating minimal widgets

Approach

  • Uses net/http/httptest for all HTTP mocking — no external dependencies needed
  • Table-driven tests where applicable
  • Tests both success and error paths for maximum coverage

- Table-driven tests for parseURL (valid URLs, edge cases, errors)
- httptest-based tests for fetchStatusData and fetchHeartbeatData
  (success, non-200, invalid JSON, connection errors)
- content() rendering tests: all-up, mixed statuses, incidents,
  unparsable dates, loading state, empty data, out-of-range status
- Settings tests: NewSettingsFromYAML with/without URL
- Full integration tests: NewWidget, Refresh with success/errors
- Coverage: 0% -> 99.0%
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