* fix: #2735

* chore: make error consistent
This commit is contained in:
Kevin Wan
2023-01-01 12:21:53 +08:00
committed by GitHub
parent c7a0ec428c
commit cf6c349118
5 changed files with 64 additions and 10 deletions

View File

@@ -223,6 +223,22 @@ func TestParseJsonBody(t *testing.T) {
assert.Equal(t, "", v.Name)
assert.Equal(t, 0, v.Age)
})
t.Run("array body", func(t *testing.T) {
var v []struct {
Name string `json:"name"`
Age int `json:"age"`
}
body := `[{"name":"kevin", "age": 18}]`
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))
r.Header.Set(ContentType, header.JsonContentType)
assert.NoError(t, ParseJsonBody(r, &v))
assert.Equal(t, 1, len(v))
assert.Equal(t, "kevin", v[0].Name)
assert.Equal(t, 18, v[0].Age)
})
}
func TestParseRequired(t *testing.T) {