Skip to content

Commit 64819a9

Browse files
committed
feat: add tests
1 parent 682dfde commit 64819a9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

bind_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ type bindTestStruct struct {
6262
SA StringArray
6363
}
6464

65+
type bindQueryArrayTestStruct struct {
66+
Foo []string `query:"foo"`
67+
}
68+
6569
type bindTestStructWithTags struct {
6670
I int `json:"I" form:"I"`
6771
PtrI *int `json:"PtrI" form:"PtrI"`
@@ -275,6 +279,30 @@ func TestBindQueryParamsCaseSensitivePrioritized(t *testing.T) {
275279
}
276280
}
277281

282+
func TestBindQueryArrayParams(t *testing.T) {
283+
e := New()
284+
req := httptest.NewRequest(http.MethodGet, "/?foo=one&foo=two", nil)
285+
rec := httptest.NewRecorder()
286+
c := e.NewContext(req, rec)
287+
q := new(bindQueryArrayTestStruct)
288+
err := c.Bind(q)
289+
if assert.NoError(t, err) {
290+
assert.Equal(t, []string{"one", "two"}, q.Foo)
291+
}
292+
}
293+
294+
func TestBindQueryArrayParamsWithSuffix(t *testing.T) {
295+
e := New()
296+
req := httptest.NewRequest(http.MethodGet, "/?foo[]=one&foo[]=two", nil)
297+
rec := httptest.NewRecorder()
298+
c := e.NewContext(req, rec)
299+
q := new(bindQueryArrayTestStruct)
300+
err := c.Bind(q)
301+
if assert.NoError(t, err) {
302+
assert.Equal(t, []string{"one", "two"}, q.Foo)
303+
}
304+
}
305+
278306
func TestBindHeaderParam(t *testing.T) {
279307
e := New()
280308
req := httptest.NewRequest(http.MethodGet, "/", nil)

0 commit comments

Comments
 (0)