From f3645e420e0ab161b4b3fddfbb1d984e3cdc3a29 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sat, 13 Aug 2022 10:31:23 +0800 Subject: [PATCH] test: add more tests (#2261) --- rest/httpc/responses_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/rest/httpc/responses_test.go b/rest/httpc/responses_test.go index b273325e..6f1a2d1e 100644 --- a/rest/httpc/responses_test.go +++ b/rest/httpc/responses_test.go @@ -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) +}