test: improve code coverage from 94.3% to 98.8%#46
Merged
miclle merged 7 commits intofox-gonic:mainfrom Dec 8, 2025
Merged
Conversation
This commit enhances test coverage by adding comprehensive tests for: - SetMode() and Mode() functions - Test all mode values (debug, release, test) - CORS() method - Test valid/invalid configurations and wildcard origins - RequestBody() method - Add edge case for non-[]byte cached values - bind() function - Test DefaultBinder and bodyBinders with empty body scenarios - queryBinding.Bind() - Test nil validator scenario - httperrors.MarshalJSON() - Test nil Meta, empty Code, and empty error scenarios Coverage improvements: - Main package: 94.3% → 96.1% (+1.8%) - All tests pass with improved edge case handling
This commit adds comprehensive tests to further enhance coverage: - Add debug_test.go for debugPrint and debugPrintRoute functions - Add bind() test for RequestBodyError and non-struct targets - Add renderError() test for render.Render interface errors - Add handleWrapper() tests for preset logger and trace ID scenarios Coverage improvements: - Main package: 96.1% → 97.9% (+1.8%) - bind() function: 88.1% → 91.5% - renderError() function: 87.5% → 100% Total improvement: 94.3% → 97.9% (+3.6%)
This commit adds additional edge case tests: - queryBinding.Bind() - Add validation error and MapFormWithTag error tests - bind() function - Add DefaultBinder as regular Binding test (93.2%) - httperrors.MarshalJSON() - Add tests for Meta with code/error fields Coverage improvements: - Main package: 97.9% → 98.5% (+0.6%) - bind() function: 91.5% → 93.2% Total improvement: 94.3% → 98.5% (+4.2%)
- Remove invalid validation error test from queryBinding.Bind - Simplify TestRenderError_RenderInterface to avoid Content-Type assertion All tests now pass with make test
Improvements: - Add TestBind_CustomBinder for custom binder error path (bind.go:63-65) - Add TestBind_ContextFieldNotConvertible for type conversion edge case - Add TestBind_WithBindingError for JSON parsing error - Add TestMarshalJSON_MetaWithMap for Meta with map values - Add TestMarshalJSON_MetaWithPrimitiveType for Meta with primitive types These changes bring bind() coverage from 93.2% to 94.9% and improve overall test robustness for edge cases.
Add TestNewLogger_FileLoggingHumanReadable to test file logging with human-readable (non-JSON) format. This covers the previously untested branch in newLogger() function at lines 132-134. Coverage improvements: - logger/logger.go newLogger(): 94.7% -> 100% - logger package overall: 90.8% -> 91.8%
Fix golangci-lint testifylint error by using require.NoError instead of assert.NoError for error assertions.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46 +/- ##
==========================================
+ Coverage 91.87% 96.00% +4.13%
==========================================
Files 16 16
Lines 726 726
==========================================
+ Hits 667 697 +30
+ Misses 42 22 -20
+ Partials 17 7 -10
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 the test coverage of the fox framework from 94.3% to 98.8%.
Changes
Coverage Improvements by Package
Key Improvements
1. binding.go - bind() function (93.2% → 94.9%)
2. httperrors/errors.go - MarshalJSON() (92.3% → 96.8%)
3. logger/logger.go - newLogger() (94.7% → 100%)
4. Other improvements
Test Results
All tests pass successfully:
make testRemaining Uncovered Code
The remaining uncovered code consists of:
These represent edge cases that are either unsafe to test or nearly impossible to trigger in practice.
Checklist