Merge pull request #51835 from thaJeztah/client_fix_TestWithUserAgent

client: fix TestWithUserAgent
This commit is contained in:
Paweł Gronowski
2026-01-09 16:26:59 +00:00
committed by GitHub

View File

@@ -301,7 +301,7 @@ func TestWithUserAgent(t *testing.T) {
t.Run("user-agent", func(t *testing.T) { t.Run("user-agent", func(t *testing.T) {
c, err := New( c, err := New(
WithUserAgent(userAgent), WithUserAgent(userAgent),
WithMockClient(func(req *http.Request) (*http.Response, error) { WithBaseMockClient(func(req *http.Request) (*http.Response, error) {
assert.Check(t, is.Equal(req.Header.Get("User-Agent"), userAgent)) assert.Check(t, is.Equal(req.Header.Get("User-Agent"), userAgent))
return &http.Response{StatusCode: http.StatusOK}, nil return &http.Response{StatusCode: http.StatusOK}, nil
}), }),
@@ -315,7 +315,7 @@ func TestWithUserAgent(t *testing.T) {
c, err := New( c, err := New(
WithUserAgent(userAgent), WithUserAgent(userAgent),
WithHTTPHeaders(map[string]string{"User-Agent": "should-be-ignored/1.0.0", "Other-Header": "hello-world"}), WithHTTPHeaders(map[string]string{"User-Agent": "should-be-ignored/1.0.0", "Other-Header": "hello-world"}),
WithMockClient(func(req *http.Request) (*http.Response, error) { WithBaseMockClient(func(req *http.Request) (*http.Response, error) {
assert.Check(t, is.Equal(req.Header.Get("User-Agent"), userAgent)) assert.Check(t, is.Equal(req.Header.Get("User-Agent"), userAgent))
assert.Check(t, is.Equal(req.Header.Get("Other-Header"), "hello-world")) assert.Check(t, is.Equal(req.Header.Get("Other-Header"), "hello-world"))
return &http.Response{StatusCode: http.StatusOK}, nil return &http.Response{StatusCode: http.StatusOK}, nil
@@ -329,7 +329,7 @@ func TestWithUserAgent(t *testing.T) {
t.Run("custom headers", func(t *testing.T) { t.Run("custom headers", func(t *testing.T) {
c, err := New( c, err := New(
WithHTTPHeaders(map[string]string{"User-Agent": "from-custom-headers/1.0.0", "Other-Header": "hello-world"}), WithHTTPHeaders(map[string]string{"User-Agent": "from-custom-headers/1.0.0", "Other-Header": "hello-world"}),
WithMockClient(func(req *http.Request) (*http.Response, error) { WithBaseMockClient(func(req *http.Request) (*http.Response, error) {
assert.Check(t, is.Equal(req.Header.Get("User-Agent"), "from-custom-headers/1.0.0")) assert.Check(t, is.Equal(req.Header.Get("User-Agent"), "from-custom-headers/1.0.0"))
assert.Check(t, is.Equal(req.Header.Get("Other-Header"), "hello-world")) assert.Check(t, is.Equal(req.Header.Get("Other-Header"), "hello-world"))
return &http.Response{StatusCode: http.StatusOK}, nil return &http.Response{StatusCode: http.StatusOK}, nil
@@ -343,7 +343,7 @@ func TestWithUserAgent(t *testing.T) {
t.Run("no user-agent set", func(t *testing.T) { t.Run("no user-agent set", func(t *testing.T) {
c, err := New( c, err := New(
WithHTTPHeaders(map[string]string{"Other-Header": "hello-world"}), WithHTTPHeaders(map[string]string{"Other-Header": "hello-world"}),
WithMockClient(func(req *http.Request) (*http.Response, error) { WithBaseMockClient(func(req *http.Request) (*http.Response, error) {
assert.Check(t, is.Equal(req.Header.Get("User-Agent"), "")) assert.Check(t, is.Equal(req.Header.Get("User-Agent"), ""))
assert.Check(t, is.Equal(req.Header.Get("Other-Header"), "hello-world")) assert.Check(t, is.Equal(req.Header.Get("Other-Header"), "hello-world"))
return &http.Response{StatusCode: http.StatusOK}, nil return &http.Response{StatusCode: http.StatusOK}, nil
@@ -358,7 +358,7 @@ func TestWithUserAgent(t *testing.T) {
c, err := New( c, err := New(
WithUserAgent(""), WithUserAgent(""),
WithHTTPHeaders(map[string]string{"User-Agent": "from-custom-headers/1.0.0", "Other-Header": "hello-world"}), WithHTTPHeaders(map[string]string{"User-Agent": "from-custom-headers/1.0.0", "Other-Header": "hello-world"}),
WithMockClient(func(req *http.Request) (*http.Response, error) { WithBaseMockClient(func(req *http.Request) (*http.Response, error) {
assert.Check(t, is.Equal(req.Header.Get("User-Agent"), "")) assert.Check(t, is.Equal(req.Header.Get("User-Agent"), ""))
assert.Check(t, is.Equal(req.Header.Get("Other-Header"), "hello-world")) assert.Check(t, is.Equal(req.Header.Get("Other-Header"), "hello-world"))
return &http.Response{StatusCode: http.StatusOK}, nil return &http.Response{StatusCode: http.StatusOK}, nil