-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
add DefaultBinder negative-path tests (multipart & non-struct) #2844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking "Sign up for GitHub", you agree to our terms of service and privacy statement. We'll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
miladev95
wants to merge
1
commit into
labstack:master
from
miladev95:test/bind-negative-multipart-nonstruct
Open
add DefaultBinder negative-path tests (multipart & non-struct) #2844
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1577,7 +1577,7 @@ func TestTimeFormatBinding(t *testing.T) { | |
| DateTimeLocal time.Time `form:"datetime_local" format:"2006-01-02T15:04"` | ||
| Date time.Time `query:"date" format:"2006-01-02"` | ||
| CustomFormat time.Time `form:"custom" format:"01/02/2006 15:04:05"` | ||
| DefaultTime time.Time `form:"default_time"` // No format tag - should use default parsing | ||
| DefaultTime time.Time `form:"default_time"` // No format tag - should use default parsing | ||
| PtrTime *time.Time `query:"ptr_time" format:"2006-01-02"` | ||
| } | ||
|
|
||
|
|
@@ -1623,7 +1623,7 @@ func TestTimeFormatBinding(t *testing.T) { | |
| { | ||
| name: "nok, wrong format should fail", | ||
| contentType: MIMEApplicationForm, | ||
| data: "datetime_local=2023-12-25", // Missing time part | ||
| data: "datetime_local=2023-12-25", // Missing time part | ||
| expectError: true, | ||
| }, | ||
| } | ||
|
|
@@ -1684,3 +1684,40 @@ func TestTimeFormatBinding(t *testing.T) { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestIsFieldMultipartFile_NonPointer_FileHeader_ReturnsError( t *testing.T) { | ||
| ok, err := isFieldMultipartFile(reflect.TypeOf(multipart.FileHeader{})) | ||
| assert.True(t, ok) | ||
| assert.Error(t, err) | ||
| assert.Contains(t, err.Error(), "binding to multipart.FileHeader struct is not supported") | ||
|
|
||
| // pointer type should be ok and no error | ||
| ok, err = isFieldMultipartFile(reflect.TypeOf((*multipart.FileHeader)(nil))) | ||
| assert.True(t, ok) | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| func TestSetMultipartFileHeaderTypes_NoFiles_ReturnsFalse(t *testing.T) { | ||
| var s struct { | ||
| Files []multipart.FileHeader | ||
| } | ||
| v := reflect.ValueOf(&s).Elem().Field(0) | ||
| ok := setMultipartFileHeaderTypes(v, "files", map[string][]*multipart.FileHeader{}) | ||
| assert.False(t, ok) | ||
| } | ||
|
|
||
| func TestDefaultBinder_bindData_NonStruct_ReturnsError(t *testing.T) { | ||
| b := &DefaultBinder{} | ||
| // destination is pointer to slice (non-struct), tag is form -> should return error | ||
| err := b.bindData(&[]int{}, map[string][]string{"a": {"1"}}, "form", nil) | ||
| assert.Error(t, err) | ||
| assert.Contains(t, err.Error(), "binding element must be a struct") | ||
|
|
||
| // for param/query/header tag should return nil (handled earlier) | ||
| err = b.bindData(&[]int{}, map[string][]string{"a": {"1"}}, "param", nil) | ||
| assert.NoError(t, err) | ||
|
|
||
| // also header | ||
| err = b.bindData(&[]int{}, map[string][]string{"a": {"1"}}, "header", nil) | ||
| assert.NoError(t, err) | ||
| } | ||
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.