diff --git a/apitest/handle.go b/apitest/handle.go index b548ade..2966ec6 100644 --- a/apitest/handle.go +++ b/apitest/handle.go @@ -9,25 +9,25 @@ import ( // RequestOption can be used to tune up http.Request. type RequestOption func(r *http.Request) -// WithHeader option adds specific header to the request. +// WithHeader option overrides specific header to the request. func WithHeader(key, value string) RequestOption { return func(r *http.Request) { - r.Header.Add(key, value) + r.Header.Set(key, value) } } -// WithContentType option adds Content-Type header to the request. +// WithContentType option overrides Content-Type header to the request. func WithContentType(contentType string) RequestOption { return func(r *http.Request) { - r.Header.Add("Content-Type", contentType) + r.Header.Set("Content-Type", contentType) } } -// WithJSONContentType option adds Content-Type header to the request +// WithJSONContentType option overrides Content-Type header to the request // with "application/json" content type. func WithJSONContentType() RequestOption { return func(r *http.Request) { - r.Header.Add("Content-Type", "application/json; charset=utf-8") + r.Header.Set("Content-Type", "application/json; charset=utf-8") } } diff --git a/apitest/handle_test.go b/apitest/handle_test.go index de41176..2b1a0de 100644 --- a/apitest/handle_test.go +++ b/apitest/handle_test.go @@ -56,7 +56,7 @@ func TestHandleRequest(t *testing.T) { t.Helper() assert.Equal(t, http.MethodGet, request.Method) assert.Equal(t, testURL, request.URL.String()) - assert.Equal(t, []string{"foo", "bar"}, request.Header["X-Test"]) + assert.Equal(t, []string{"bar"}, request.Header["X-Test"]) }, }, {