Skip to content

Add unit tests for ipinfo module (0% to 82.7% coverage) - #2157

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

Add unit tests for ipinfo module (0% to 82.7% coverage)#2157
Seanstoppable wants to merge 1 commit into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-ipinfo-test-coverage

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

Adds comprehensive unit tests for modules/ipaddresses/ipinfo, bringing coverage from 0% to 82.7%.

Changes

widget.go

  • Added httpClient and baseURL fields to Widget struct for dependency injection in tests
  • Fixed Authorization header format string (was corrupted/non-functional)

widget_test.go (new)

14 test functions using net/http/httptest and table-driven patterns:

  • API interaction: successful parse, partial response, empty response
  • Headers: Authorization (with/without token), User-Agent
  • Error paths: invalid JSON, connection errors
  • Display formatting: setResult with full/empty/partial data, formatableText
  • Protocol version: String(), toNetwork(), newProtocolVersion() parsing
  • Settings: NewSettingsFromYAML with defaults, token, and all protocol versions

Coverage

```n
Remaining uncovered: `getMyIP()` (requires network dial), `NewWidget`/`Refresh` (require `tview.Application`).

- Add httpClient and baseURL fields to Widget for testability
- Fix Authorization header format string (was corrupted asterisks)
- Test successful IP data parsing and display formatting
- Test Authorization header with and without token
- Test User-Agent header
- Test error paths: invalid JSON, connection errors
- Test setResult formatting with full, empty, and partial data
- Test formatableText template generation
- Test protocolVersion String() and toNetwork() methods
- Test newProtocolVersion parsing with valid and invalid inputs
- Test NewSettingsFromYAML with defaults, tokens, and protocol versions
- All tests use httptest for API mocking, table-driven where appropriate
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