test: improve code coverage from 90.6% to 94.0%#45
Merged
miclle merged 2 commits intofox-gonic:mainfrom Dec 8, 2025
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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:
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:
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:
Test Statistics
New Tests Added:
Functions Improved to 100%:
DELETE()- HTTP method shortcutPUT()- HTTP method shortcutPATCH()- HTTP method shortcutOPTIONS()- HTTP method shortcutHEAD()- HTTP method shortcutAny()- All HTTP methods handlerNotFound()- Custom 404 handlerNoRoute()- Route not found handlerNoMethod()- Method not allowed handlerLoad()- Router config loaderLast()- HandlersChain last handlerfilterFlags()- Content-Type filterRemaining Uncovered Code
The remaining uncovered code consists mainly of:
These are either not suitable for unit testing or have low priority.
Test Execution
All tests pass successfully:
make testOutput:
Impact
Verification
After merge, Codecov badge will update to show ~94% coverage.