Skip to content

🧪 test: Add comprehensive tests for binding to pointer scalar types#4191

Merged
ReneWerner87 merged 6 commits into
mainfrom
claude/fix-bind-to-pointer-issue
Apr 7, 2026
Merged

🧪 test: Add comprehensive tests for binding to pointer scalar types#4191
ReneWerner87 merged 6 commits into
mainfrom
claude/fix-bind-to-pointer-issue

Conversation

@Claude

@Claude Claude AI commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Description

The issue raised concerns about binding integer values from frontend requests to pointer types like *int64 in 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 Coverage: Added comprehensive tests covering:
    • Test_QueryBinder_Bind_PointerScalars and Test_FormBinder_Bind_PointerScalars covering *int64, *string, *bool, *float64
    • All fields provided: pointers are non-nil with correct values
    • No fields provided: pointers remain nil (vs zero values for non-pointers)
    • Partial fields: only provided fields have non-nil pointers
    • Explicit zero/empty values provided (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, and Test_JSON_Binding_Bind_OptionalIDParam testing the exact use-case from the original issue with OptionalIDParam struct containing IDPtr *int64 with appropriate struct tags (query, form, and json)

Example usage:

// Query/Form binding
type Query struct {
    ID     *int64  `query:"id"`
    Name   *string `query:"name"`
    Active *bool   `query:"active"`
}

// JSON binding (from original issue)
type OptionalIDParam struct {
    IDPtr *int64 `json:"id"`
}

// When ?id=123&name=test is sent:
// - ID is non-nil with value 123
// - Name is non-nil with value "test"
// - Active is nil (not provided)

// When ?id=0&name= is sent:
// - ID is non-nil with value 0
// - Name is non-nil with value ""
// - Active is nil (not provided)

// When {"id":null} is sent in JSON:
// - IDPtr is nil (explicit null)

// vs non-pointer int64 which would be 0 when not provided

The key advantage: pointer types distinguish between "not sent" (nil) and "zero value" (0, "", false).

  • Benchmarks: N/A - test-only change
  • Documentation Update: N/A - behavior already supported
  • Changelog/What's New: N/A - test-only change
  • Migration Guide: N/A - no API changes
  • API Alignment with Express: N/A
  • API Longevity: Test coverage ensures stability
  • Examples: Test cases serve as examples

Type of change

  • New feature (non-breaking change which adds functionality)
  • Enhancement (improvement to existing features and functionality)
  • Documentation update (changes to documentation)
  • Performance improvement (non-breaking change which improves efficiency)
  • Code consistency (non-breaking change which improves code reliability and robustness)

Checklist

Before you submit your pull request, please make sure you meet these requirements:

  • Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Updated the documentation in the /docs/ directory for Fiber's documentation.
  • Added or updated unit tests to validate the effectiveness of the changes or new features.
  • Ensured that new and existing unit tests pass locally with the changes.
  • Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.
  • Aimed for optimal performance with minimal allocations in the new code.
  • Provided benchmarks for the new code to analyze and improve upon.

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

@Claude Claude AI assigned Claude and gaby Apr 6, 2026
@Claude Claude AI linked an issue Apr 6, 2026 that may be closed by this pull request
3 tasks
@ReneWerner87 ReneWerner87 added this to v3 Apr 6, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Apr 6, 2026
@Claude Claude AI changed the title [WIP] Fix binding to pointer issue in v3 🧪 test: Add comprehensive tests for binding to pointer scalar types Apr 6, 2026
Claude finished work on behalf of gaby April 6, 2026 15:25
@Claude Claude AI requested a review from gaby April 6, 2026 15:25
@codecov

codecov Bot commented Apr 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.23%. Comparing base (7376f58) to head (48960a6).
⚠️ Report is 10 commits behind head on main.

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     
Flag Coverage Δ
unittests 91.23% <ø> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@gaby gaby marked this pull request as ready for review April 6, 2026 15:29
@gaby gaby requested a review from a team as a code owner April 6, 2026 15:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_PointerScalars covering pointer scalar binding via query string.
  • Add Test_FormBinder_Bind_PointerScalars covering 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.

Comment thread binder/query_test.go
Comment thread binder/query_test.go
Comment thread binder/form_test.go
@gaby

gaby commented Apr 6, 2026

Copy link
Copy Markdown
Member

@copilot apply changes based on the comments in this thread

Copilot AI commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

@copilot apply changes based on the comments in this thread

Added "zero values provided" subtests to both Test_QueryBinder_Bind_PointerScalars (query_test.go) and Test_FormBinder_Bind_PointerScalars (form_test.go) in commit 935b749. These subtests send explicit zero/empty values (id=0&name=&active=false&score=0) and assert that all pointers are non-nil with the correct zero values.

Copilot finished work on behalf of gaby April 6, 2026 15:35
Copilot AI requested a review from gaby April 6, 2026 15:35
@Claude

Claude AI commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

@claude[agent] golangci-lint is failing

Fixed in commit dcdd42a. Replaced require.Equal(t, "", *f.Name) and require.Equal(t, "", *q.Name) with require.Empty(t, *f.Name) and require.Empty(t, *q.Name) to satisfy the testifylint linter.

@Claude Claude AI changed the title 🧪 test: Add comprehensive tests for binding to pointer scalar types Addressing PR comments Apr 7, 2026
Claude finished work on behalf of gaby April 7, 2026 03:59
@gaby gaby changed the title Addressing PR comments 🧪 test: Add comprehensive tests for binding to pointer scalar types Apr 7, 2026
@gaby

gaby commented Apr 7, 2026

Copy link
Copy Markdown
Member

@claude[agent] Also add tests for the use-case from the original issue:

type OptionalIDParam struct {
	IDPtr *int64 `json:"id"`
}

@Claude

Claude AI commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

@claude[agent] Also add tests for the use-case from the original issue:

...

Added in commit 77f5c18. Created Test_QueryBinder_Bind_OptionalIDParam and Test_FormBinder_Bind_OptionalIDParam that test the exact use-case from the original issue with an OptionalIDParam struct containing IDPtr *int64. Tests cover three scenarios: id provided, id not provided (nil), and id=0 (non-nil pointer with zero value).

@Claude Claude AI changed the title 🧪 test: Add comprehensive tests for binding to pointer scalar types 🧪 test: Add comprehensive tests for binding to pointer scalar types Apr 7, 2026
@Claude Claude AI requested a review from gaby April 7, 2026 04:43
Claude finished work on behalf of gaby April 7, 2026 04:43
@gaby

gaby commented Apr 7, 2026

Copy link
Copy Markdown
Member

@claude[agent] Also add tests for the use-case from the original issue:

...

Added in commit 77f5c18. Created Test_QueryBinder_Bind_OptionalIDParam and Test_FormBinder_Bind_OptionalIDParam that test the exact use-case from the original issue with an OptionalIDParam struct containing IDPtr *int64. Tests cover three scenarios: id provided, id not provided (nil), and id=0 (non-nil pointer with zero value).

@claude[agent] the issue uses json tag.

@Claude

Claude AI commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

@claude[agent] Also add tests for the use-case from the original issue:

...
...

Fixed in commit 48960a6. Added Test_JSON_Binding_Bind_OptionalIDParam with the correct json:"id" tag as specified in the original issue. The test covers four scenarios: id provided (123), id not provided (empty object), id zero (0), and id null (explicit null in JSON).

Claude finished work on behalf of gaby April 7, 2026 04:58
@ReneWerner87 ReneWerner87 merged commit 4ea5bef into main Apr 7, 2026
20 checks passed
@ReneWerner87 ReneWerner87 deleted the claude/fix-bind-to-pointer-issue branch April 7, 2026 10:35
@github-project-automation github-project-automation Bot moved this to Done in v3 Apr 7, 2026
@welcome

welcome Bot commented Apr 7, 2026

Copy link
Copy Markdown

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

@ReneWerner87 ReneWerner87 modified the milestones: v3, v3.2.0 Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🤗 [Question]: bind to pointer

5 participants