mirror of
https://github.com/labstack/echo.git
synced 2025-11-25 22:32:23 +02:00
17
bind_test.go
17
bind_test.go
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user