test: add more tests (#2261)

master
Kevin Wan 2 years ago committed by GitHub
parent 62abac0b7e
commit f3645e420e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -63,3 +63,23 @@ func TestParseNoBody(t *testing.T) {
assert.Nil(t, Parse(resp, &val))
assert.Equal(t, "bar", val.Foo)
}
func TestParseWithZeroValue(t *testing.T) {
var val struct {
Foo int `header:"foo"`
Bar int `json:"bar"`
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("foo", "0")
w.Header().Set(header.ContentType, header.JsonContentType)
w.Write([]byte(`{"bar":0}`))
}))
defer svr.Close()
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
assert.Nil(t, err)
resp, err := DoRequest(req)
assert.Nil(t, err)
assert.Nil(t, Parse(resp, &val))
assert.Equal(t, 0, val.Foo)
assert.Equal(t, 0, val.Bar)
}

Loading…
Cancel
Save