🧪 test: Add comprehensive tests for binding to pointer scalar types#4191
Conversation
Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/fc708a19-7650-4235-b8dd-aa24031d27b6 Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4191 +/- ##
==========================================
+ Coverage 91.18% 91.23% +0.05%
==========================================
Files 123 123
Lines 11847 11847
==========================================
+ Hits 10803 10809 +6
+ Misses 658 653 -5
+ Partials 386 385 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds missing unit test coverage for Fiber v3 binders to ensure query/form binding correctly populates pointer scalar fields (distinguishing “not provided” as nil vs “provided” as non-nil), helping prevent regressions in binder behavior.
Changes:
- Add
Test_QueryBinder_Bind_PointerScalarscovering pointer scalar binding via query string. - Add
Test_FormBinder_Bind_PointerScalarscovering pointer scalar binding via URL-encoded form body.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| binder/query_test.go | Adds query binder tests for *int64, *string, *bool, *float64 across all/none/partial inputs. |
| binder/form_test.go | Adds form binder tests for *int64, *string, *bool, *float64 across all/none/partial inputs. |
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/93312b5c-35d9-4e1c-b8ab-90ad4d030b40 Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Added "zero values provided" subtests to both |
Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/4f8aca24-e8bf-4cfd-a315-90945ade208a Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Fixed in commit dcdd42a. Replaced |
|
@claude[agent] Also add tests for the use-case from the original issue: type OptionalIDParam struct {
IDPtr *int64 `json:"id"`
} |
Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/792b7351-b5a1-448d-82e9-09522f31a3ac Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
... Added in commit 77f5c18. Created |
@claude[agent] the issue uses |
Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/0089f956-fdaf-49c0-a5c0-3edf3ae8e1c1 Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Fixed in commit 48960a6. Added |
|
Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Description
The issue raised concerns about binding integer values from frontend requests to pointer types like
*int64in Fiber v3. Testing confirms this functionality works correctly. However, the test suite lacked coverage for pointer scalar types, making it difficult to verify behavior and prevent regressions.This PR adds comprehensive test coverage demonstrating that binding to pointer scalar types works as expected in Fiber v3, including tests for the specific use-case from the original issue across all binder types (Query, Form, and JSON).
Changes introduced
Test_QueryBinder_Bind_PointerScalarsandTest_FormBinder_Bind_PointerScalarscovering*int64,*string,*bool,*float64nil(vs zero values for non-pointers)id=0&name=&active=false&score=0): pointers are non-nil with correct zero values, distinguishing "explicitly sent zero" from "not sent at all"Test_QueryBinder_Bind_OptionalIDParam,Test_FormBinder_Bind_OptionalIDParam, andTest_JSON_Binding_Bind_OptionalIDParamtesting the exact use-case from the original issue withOptionalIDParamstruct containingIDPtr *int64with appropriate struct tags (query,form, andjson)Example usage:
The key advantage: pointer types distinguish between "not sent" (nil) and "zero value" (0, "", false).
Type of change
Checklist
Before you submit your pull request, please make sure you meet these requirements:
/docs/directory for Fiber's documentation.Commit formatting
Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md