|
|
@ -196,6 +196,9 @@ Content-Disposition: form-data; name="age"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestParseJsonBody(t *testing.T) {
|
|
|
|
func TestParseJsonBody(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("has body", func(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
var v struct {
|
|
|
|
var v struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Age int `json:"age"`
|
|
|
|
Age int `json:"age"`
|
|
|
@ -208,6 +211,23 @@ func TestParseJsonBody(t *testing.T) {
|
|
|
|
assert.Nil(t, Parse(r, &v))
|
|
|
|
assert.Nil(t, Parse(r, &v))
|
|
|
|
assert.Equal(t, "kevin", v.Name)
|
|
|
|
assert.Equal(t, "kevin", v.Name)
|
|
|
|
assert.Equal(t, 18, v.Age)
|
|
|
|
assert.Equal(t, 18, v.Age)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("hasn't body", func(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var v struct {
|
|
|
|
|
|
|
|
Name string `json:"name,optional"`
|
|
|
|
|
|
|
|
Age int `json:"age,optional"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
|
|
|
|
|
|
assert.Nil(t, Parse(r, &v))
|
|
|
|
|
|
|
|
assert.Equal(t, "", v.Name)
|
|
|
|
|
|
|
|
assert.Equal(t, 0, v.Age)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestParseRequired(t *testing.T) {
|
|
|
|
func TestParseRequired(t *testing.T) {
|
|
|
|