Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kolaente committed Jan 24, 2025
1 parent 682dfde commit 64819a9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 64819a9

Please sign in to comment.