MCPcopy
hub / github.com/labstack/echo / TestToMultipleFields

Function TestToMultipleFields

bind_test.go:177–200  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

175}
176
177func TestToMultipleFields(t *testing.T) {
178 e := New()
179 req := httptest.NewRequest(http.MethodGet, "/?id=1&ID=2", nil)
180 rec := httptest.NewRecorder()
181 c := e.NewContext(req, rec)
182
183 type Root struct {
184 ID int64 `query:"id"`
185 Child2 struct {
186 ID int64
187 }
188 Child1 struct {
189 ID int64 `query:"id"`
190 }
191 }
192
193 u := new(Root)
194 err := c.Bind(u)
195 if assert.NoError(t, err) {
196 assert.Equal(t, int64(1), u.ID) // perfectly reasonable
197 assert.Equal(t, int64(1), u.Child1.ID) // untagged struct containing tagged field gets filled (by tag)
198 assert.Equal(t, int64(0), u.Child2.ID) // untagged struct containing untagged field should not be bind
199 }
200}
201
202func TestBindJSON(t *testing.T) {
203 testBindOkay(t, strings.NewReader(userJSON), nil, MIMEApplicationJSON)

Callers

nothing calls this directly

Calls 3

BindMethod · 0.95
NewFunction · 0.85
NewContextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…