From f60c3a624a6511dfdce1316b52ed11b74710643b Mon Sep 17 00:00:00 2001 From: Robert Wu <94589791+tongoss@users.noreply.github.com> Date: Thu, 3 Apr 2025 05:43:57 -0400 Subject: [PATCH] Add a unit test to verify the functionality of WithClient for zipkin exporter (#6576) fix #6533 Co-authored-by: Damien Mathieu <42@dmathieu.com> --- exporters/zipkin/zipkin_test.go | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/exporters/zipkin/zipkin_test.go b/exporters/zipkin/zipkin_test.go index ad016548e..6a2b49180 100644 --- a/exporters/zipkin/zipkin_test.go +++ b/exporters/zipkin/zipkin_test.go @@ -425,3 +425,38 @@ func TestWithHeaders(t *testing.T) { assert.Equal(t, headers["name1"], req.Header.Get("name1")) assert.Equal(t, headers["name2"], req.Header.Get("name2")) } + +func TestWithClient(t *testing.T) { + customClient := &http.Client{ + Timeout: 1000, + } + + testcases := []struct { + name string + client *http.Client + want *http.Client + description string + }{ + { + name: "nil client", + client: nil, + want: http.DefaultClient, + description: "should fall back to default client when nil is provided", + }, + { + name: "custom client", + client: customClient, + want: customClient, + description: "should use provided custom client", + }, + } + + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + exp, err := New("", WithClient(tc.client)) + require.NoError(t, err) + + assert.Equal(t, tc.want, exp.client) + }) + } +}