(t *testing.T, r io.Reader, ctype string, expectedInternal error)
| 735 | } |
| 736 | |
| 737 | func 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 | |
| 761 | func TestDefaultBinder_BindToStructFromMixedSources(t *testing.T) { |
| 762 | // tests to check binding behaviour when multiple sources (path params, query params and request body) are in use |
no test coverage detected
searching dependent graphs…