Skip to content

test: improve code coverage from 90.6% to 94.0%#45

Merged
miclle merged 2 commits intofox-gonic:mainfrom
miclle:test/improve-coverage
Dec 8, 2025
Merged

test: improve code coverage from 90.6% to 94.0%#45
miclle merged 2 commits intofox-gonic:mainfrom
miclle:test/improve-coverage

Conversation

@miclle
Copy link
Copy Markdown
Member

@miclle miclle commented Dec 8, 2025

Summary

This PR significantly improves test coverage by adding comprehensive tests for previously untested functions, increasing overall coverage from 90.6% to 94.0% (+3.4%).

Coverage Improvements

Category Before After Improvement
Total Coverage 90.6% 94.0% +3.4% ✅
Functions at 100% - +12 functions

Changes by Category

1. HTTP Method Tests (routergroup_test.go)

Added comprehensive tests for all HTTP method shortcuts:

  • DELETE() - 0% → 100%
  • PUT() - 0% → 100%
  • PATCH() - 0% → 100%
  • OPTIONS() - 0% → 100%
  • HEAD() - 0% → 100%
  • Any() - 0% → 100% (tests all 9 HTTP methods)

Test Coverage:

  • Tests each method with proper request/response validation
  • Validates Any() works for GET, POST, PUT, DELETE, PATCH, etc.

2. Engine Configuration Tests (engine_test.go)

Added tests for engine configuration methods:

  • NotFound() - Custom 404 handler (0% → 100%)
  • NoRoute() - Route not found handler (0% → 100%)
  • NoMethod() - 405 method not allowed handler (0% → 100%)
  • Load() - Router config loader (0% → 100%)
  • HandlersChain.Last() - Edge cases (66.7% → 100%)

Test Coverage:

  • Custom error handlers with JSON responses
  • Method not allowed with proper status codes
  • Router configuration loading
  • HandlersChain edge cases (empty, single, multiple handlers)

3. Binding Function Tests (binding_test.go)

Added tests for binding utility functions:

  • filterFlags() - Content-Type parsing (75% → 100%)
  • queryBinding.Name() - Binding name (0% → 100%)
  • queryBinding.Bind() - Query parameter binding (66.7% → 100%)

Test Coverage:

  • Filter flags with spaces, semicolons, and edge cases
  • Query binding with various parameter combinations
  • Validation and error handling

Test Statistics

New Tests Added:

  • 10 new test functions
  • 30+ test cases
  • 294 lines of test code

Functions Improved to 100%:

  1. DELETE() - HTTP method shortcut
  2. PUT() - HTTP method shortcut
  3. PATCH() - HTTP method shortcut
  4. OPTIONS() - HTTP method shortcut
  5. HEAD() - HTTP method shortcut
  6. Any() - All HTTP methods handler
  7. NotFound() - Custom 404 handler
  8. NoRoute() - Route not found handler
  9. NoMethod() - Method not allowed handler
  10. Load() - Router config loader
  11. Last() - HandlersChain last handler
  12. filterFlags() - Content-Type filter

Remaining Uncovered Code

The remaining uncovered code consists mainly of:

  • Fatal/Panic logger methods - Not testable (would exit/panic process)
  • Debug/Mode setters - Environment-specific functions
  • CORS configuration - Requires CORS middleware setup

These are either not suitable for unit testing or have low priority.

Test Execution

All tests pass successfully:

make test

Output:

✓ Tests passed
Total coverage: 94.0%

Impact

  • ✅ Increased confidence in HTTP method handlers
  • ✅ Improved coverage of engine configuration
  • ✅ Better test coverage for binding utilities
  • ✅ More robust error handling validation
  • ✅ Comprehensive edge case testing

Verification

After merge, Codecov badge will update to show ~94% coverage.

Add comprehensive test coverage for previously untested functions:

HTTP Methods (routergroup_test.go):
- Added tests for DELETE, PUT, PATCH, OPTIONS, HEAD methods
- Added tests for Any() method covering all HTTP verbs
- All method shortcuts now have 100% coverage

Engine Configuration (engine_test.go):
- Added tests for NotFound() custom 404 handler
- Added tests for NoRoute() handler
- Added tests for NoMethod() handler with 405 responses
- Added tests for Load() router config function
- Added tests for HandlersChain.Last() edge cases (empty, single, multiple)

Binding Functions (binding_test.go):
- Added tests for filterFlags() with various inputs
- Added tests for queryBinding Name() and Bind() methods
- Improved coverage of binding edge cases

Coverage Improvements:
- Total coverage: 90.6% → 94.0% (+3.4%)
- 12 previously uncovered functions now at 100%
- Reduced uncovered functions significantly

All tests pass successfully with improved reliability.
Replace assert.Equal(t, "", args.Keyword) with assert.Empty(t, args.Keyword)
to comply with testifylint linter requirements.

This fixes the CI lint failure.
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.87%. Comparing base (1a48912) to head (19fb648).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #45      +/-   ##
==========================================
+ Coverage   87.87%   91.87%   +3.99%     
==========================================
  Files          16       16              
  Lines         726      726              
==========================================
+ Hits          638      667      +29     
+ Misses         70       42      -28     
+ Partials       18       17       -1     
Flag Coverage Δ
unittests 91.87% <ø> (+3.99%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@miclle miclle merged commit 56ab157 into fox-gonic:main Dec 8, 2025
10 checks passed
@miclle miclle deleted the test/improve-coverage branch December 8, 2025 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant