Skip to content

Add unit tests for modules/ipaddresses/ipapi (0% → 83.7% coverage) - #2154

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

Add unit tests for modules/ipaddresses/ipapi (0% → 83.7% coverage)#2154
Seanstoppable wants to merge 1 commit into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-ipapi-test-coverage

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

Adds unit tests for the modules/ipaddresses/ipapi package, bringing test coverage from 0% to 83.7%.

Changes

  • widget_test.go — 16 tests covering:
    • formatableText output formatting
    • setResult with default/custom args, color settings, empty data, invalid args
    • ipinfo() HTTP integration via httptest (success, invalid JSON, connection errors, invalid URLs, empty responses, full realistic response parsing)
    • argLookup map completeness
  • settings_test.go — 4 tests covering:
    • Default settings (colors, args, constants)
    • Custom color configuration
    • Args parsing from YAML
  • widget.go — Minor refactor: extracted apiURL field with defaultAPIURL constant so the HTTP endpoint is injectable in tests. No behavior change in production.

Testing

$ go test ./modules/ipaddresses/ipapi/ -cover
PASS
coverage: 83.7% of statements
ok  	github.com/wtfutil/wtf/modules/ipaddresses/ipapi

- Add widget_test.go with httptest-based API mocking
- Add settings_test.go for configuration parsing
- Test IP data parsing, display formatting, color settings, error paths
- Table-driven tests for custom args and field filtering
- Make apiURL injectable on Widget for testability (no behavior change)
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