Skip to content

Commit

Permalink
added testing for empty Content-Type
Browse files Browse the repository at this point in the history
  • Loading branch information
calgor committed Apr 18, 2023
1 parent bfe99ab commit 774c166
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ func TestBindUnsupportedMediaType(t *testing.T) {
testBindError(t, strings.NewReader(invalidContent), MIMEApplicationJSON, &json.SyntaxError{})
}

func TestBindErrEmptyContentType(t *testing.T) {
testBindError(t, strings.NewReader(invalidContent), "", errors.New("missing content type header"))
}

func TestBindbindData(t *testing.T) {
ts := new(bindTestStruct)
b := new(DefaultBinder)
Expand Down Expand Up @@ -674,6 +678,11 @@ func testBindError(t *testing.T, r io.Reader, ctype string, expectedInternal err
assert.Equal(t, http.StatusBadRequest, err.(*HTTPError).Code)
assert.IsType(t, expectedInternal, err.(*HTTPError).Internal)
}
case ctype == "": // no content type
if assert.IsType(t, new(HTTPError), err) {
assert.Equal(t, ErrEmptyContentType, err)
assert.IsType(t, expectedInternal, err.(*HTTPError).Internal)
}
default:
if assert.IsType(t, new(HTTPError), err) {
assert.Equal(t, ErrUnsupportedMediaType, err)
Expand Down
3 changes: 2 additions & 1 deletion binder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/stretchr/testify/assert"
"io"
"math/big"
"net/http"
Expand All @@ -13,6 +12,8 @@ import (
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func createTestContext(URL string, body io.Reader, pathParams map[string]string) Context {
Expand Down

0 comments on commit 774c166

Please sign in to comment.