Regression test for #2629: when binding form data fails a type conversion, the returned error must identify which field failed (so applications can render a useful message), instead of a bare strconv error with no field context.
(t *testing.T)
| 16 | // returned error must identify which field failed (so applications can render a |
| 17 | // useful message), instead of a bare strconv error with no field context. |
| 18 | func TestBind_formConversionErrorIncludesFieldName(t *testing.T) { |
| 19 | e := New() |
| 20 | req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader("number=10a")) |
| 21 | req.Header.Set(HeaderContentType, MIMEApplicationForm) |
| 22 | c := e.NewContext(req, httptest.NewRecorder()) |
| 23 | |
| 24 | type DTO struct { |
| 25 | Number int `form:"number"` |
| 26 | } |
| 27 | var dto DTO |
| 28 | err := c.Bind(&dto) |
| 29 | |
| 30 | assert.Error(t, err) |
| 31 | assert.ErrorContains(t, err, "number", "bind error must identify the failing field") |
| 32 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…