From 64819a9f2b8d3e58391a67b0d6a6042e1c75e43a Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 24 Jan 2025 13:18:50 +0100 Subject: [PATCH] feat: add tests --- bind_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bind_test.go b/bind_test.go index 303c8854a..90adabf2c 100644 --- a/bind_test.go +++ b/bind_test.go @@ -62,6 +62,10 @@ type bindTestStruct struct { SA StringArray } +type bindQueryArrayTestStruct struct { + Foo []string `query:"foo"` +} + type bindTestStructWithTags struct { I int `json:"I" form:"I"` PtrI *int `json:"PtrI" form:"PtrI"` @@ -275,6 +279,30 @@ func TestBindQueryParamsCaseSensitivePrioritized(t *testing.T) { } } +func TestBindQueryArrayParams(t *testing.T) { + e := New() + req := httptest.NewRequest(http.MethodGet, "/?foo=one&foo=two", nil) + rec := httptest.NewRecorder() + c := e.NewContext(req, rec) + q := new(bindQueryArrayTestStruct) + err := c.Bind(q) + if assert.NoError(t, err) { + assert.Equal(t, []string{"one", "two"}, q.Foo) + } +} + +func TestBindQueryArrayParamsWithSuffix(t *testing.T) { + e := New() + req := httptest.NewRequest(http.MethodGet, "/?foo[]=one&foo[]=two", nil) + rec := httptest.NewRecorder() + c := e.NewContext(req, rec) + q := new(bindQueryArrayTestStruct) + err := c.Bind(q) + if assert.NoError(t, err) { + assert.Equal(t, []string{"one", "two"}, q.Foo) + } +} + func TestBindHeaderParam(t *testing.T) { e := New() req := httptest.NewRequest(http.MethodGet, "/", nil)