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

Function testBindError

bind_test.go:737–759  ·  view source on GitHub ↗
(t *testing.T, r io.Reader, ctype string, expectedInternal error)

Source from the content-addressed store, hash-verified

735}
736
737func testBindError(t *testing.T, r io.Reader, ctype string, expectedInternal error) {
738 e := New()
739 req := httptest.NewRequest(http.MethodPost, "/", r)
740 rec := httptest.NewRecorder()
741 c := e.NewContext(req, rec)
742 req.Header.Set(HeaderContentType, ctype)
743 u := new(user)
744 err := c.Bind(u)
745
746 switch {
747 case strings.HasPrefix(ctype, MIMEApplicationJSON), strings.HasPrefix(ctype, MIMEApplicationXML), strings.HasPrefix(ctype, MIMETextXML),
748 strings.HasPrefix(ctype, MIMEApplicationForm), strings.HasPrefix(ctype, MIMEMultipartForm):
749 if assert.IsType(t, new(HTTPError), err) {
750 assert.Equal(t, http.StatusBadRequest, err.(*HTTPError).Code)
751 assert.IsType(t, expectedInternal, err.(*HTTPError).Unwrap())
752 }
753 default:
754 if assert.IsType(t, new(HTTPError), err) {
755 assert.Equal(t, ErrUnsupportedMediaType, err)
756 assert.IsType(t, expectedInternal, err.(*HTTPError).Unwrap())
757 }
758 }
759}
760
761func TestDefaultBinder_BindToStructFromMixedSources(t *testing.T) {
762 // tests to check binding behaviour when multiple sources (path params, query params and request body) are in use

Callers 3

TestBindJSONFunction · 0.85
TestBindXMLFunction · 0.85

Calls 5

BindMethod · 0.95
NewFunction · 0.85
NewContextMethod · 0.80
SetMethod · 0.80
UnwrapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…