1
0
mirror of https://github.com/labstack/echo.git synced 2025-11-25 22:32:23 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2017-08-02 23:16:11 -07:00
parent f8c3008787
commit b42edd791f
3 changed files with 25 additions and 1 deletions

View File

@@ -118,6 +118,7 @@ var values = map[string][]string{
func TestBindJSON(t *testing.T) {
testBindOkay(t, strings.NewReader(userJSON), MIMEApplicationJSON)
testBindError(t, strings.NewReader(invalidContent), MIMEApplicationJSON)
testBindSlice(t, strings.NewReader(userJSONArray), MIMEApplicationJSON)
}
func TestBindXML(t *testing.T) {
@@ -349,3 +350,19 @@ func testBindError(t *testing.T, r io.Reader, ctype string) {
}
}
}
func testBindSlice(t *testing.T, r io.Reader, ctype string) {
e := New()
req := httptest.NewRequest(POST, "/", r)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
req.Header.Set(HeaderContentType, ctype)
us := []user{}
err := c.Bind(&us)
if assert.NoError(t, err) {
assert.Equal(t, 1, us[0].ID)
assert.Equal(t, "Jon Snow", us[0].Name)
assert.Equal(t, 2, us[1].ID)
assert.Equal(t, "Arya Stark", us[1].Name)
}
}