Skip to content

Add unit tests for modules/nextbus (0% → 80.5% coverage) - #2152

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

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

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

Adds comprehensive unit tests for the modules/nextbus package, bringing coverage from 0% to 80.5%.

Changes

  • widget.go: Extract baseURL as a package-level variable to enable httptest injection for testing
  • widget_test.go (new): Comprehensive test suite

Test Coverage

Function Coverage
strTimeToInt 100%
getNextBus 92.9%
NewSettingsFromYAML 100%
ConfigText 100%

Tests Added

  • TestStrTimeToInt — Table-driven tests for time formatting (zero values, whole minutes, remainder seconds, non-numeric input)
  • TestGetNextBus_ArrayResponse — Multiple predictions parsed from JSON array
  • TestGetNextBus_SingleObjectResponse — Single prediction parsed from JSON object
  • TestGetNextBus_HTTPError — Connection reset error handling
  • TestGetNextBus_InvalidJSON — Malformed response body
  • TestGetNextBus_InvalidPredictionRaw — Prediction field is neither object nor array
  • TestGetNextBus_EmptyPredictions — Empty array edge case
  • TestGetNextBus_ServerDown — Unreachable server
  • TestSettingsDefaults — Package constants
  • TestNewSettingsFromYAML — Settings parsing with values
  • TestNewSettingsFromYAML_Defaults — Settings parsing with empty config

- Add table-driven tests for strTimeToInt time formatting
- Use httptest to mock NextBus JSON API responses
- Test array and single-object prediction parsing
- Test HTTP error, invalid JSON, and connection failure paths
- Test empty predictions edge case
- Test NewSettingsFromYAML with values and defaults
- Test ConfigText helper output
- Extract baseURL as package var to enable httptest injection
@Seanstoppable
Seanstoppable force-pushed the seanstoppable-nextbus-test-coverage branch from cc76558 to d78d5ad Compare July 26, 2026 06:29
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