Skip to content

Add unit tests for all cryptocurrency sub-modules - #2163

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

Add unit tests for all cryptocurrency sub-modules#2163
Seanstoppable wants to merge 1 commit into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-crypto-test-coverage

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

Add comprehensive test coverage for all 6 cryptocurrency sub-modules, which previously had 0% coverage.

Coverage Results

Package Coverage
cryptolive/price 75.0%
cryptolive/toplist 70.8%
mempool 68.0%
cryptolive 50.0%
bittrex 29.5%
blockfolio 23.9%

Test Approach

  • net/http/httptest to mock crypto API responses
  • Table-driven tests throughout
  • JSON response parsing and struct deserialization
  • HTTP request construction and URL formatting
  • Price formatting and display logic
  • Settings initialization from YAML config
  • Error handling (network errors, invalid JSON, API failures)

Bug Fixes Discovered During Testing

  • cryptolive/price: Report API errors (e.g. 401 Unauthorized) instead of silently showing zero prices
  • cryptolive/toplist: Remove os.Exit(1) on JSON decode error — report errors gracefully instead of crashing the entire application

Notes

Remaining uncovered code is primarily tview widget lifecycle methods (Refresh/display/content/NewWidget) that require a full terminal UI environment to instantiate.

Add comprehensive test coverage for:
- modules/cryptocurrency/bittrex (29.5%)
- modules/cryptocurrency/blockfolio (23.9%)
- modules/cryptocurrency/cryptolive (50.0%)
- modules/cryptocurrency/cryptolive/price (75.0%)
- modules/cryptocurrency/cryptolive/toplist (70.8%)
- modules/cryptocurrency/mempool (68.0%)

Tests use net/http/httptest to mock crypto APIs and cover:
- JSON response parsing and struct deserialization
- HTTP request construction and URL formatting
- Price formatting and display logic
- Settings initialization from YAML config
- Error handling (network errors, invalid JSON, API failures)
- Table-driven test patterns throughout

Also fixes bugs in source code discovered during testing:
- cryptolive/price: Report API errors instead of showing zero prices
- cryptolive/toplist: Remove os.Exit(1) on JSON decode error, report
  errors gracefully instead of crashing the entire application
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