From 3b5b7940e1533276bc147fa91fd943629549d60f Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Thu, 12 Oct 2023 12:27:12 -0400 Subject: [PATCH] tracer TestWithHeaderTags: Clear header tags to work with -count=2 (#2262) --- ddtrace/tracer/option_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ddtrace/tracer/option_test.go b/ddtrace/tracer/option_test.go index 3d8e23c7d6..8c06d879ae 100644 --- a/ddtrace/tracer/option_test.go +++ b/ddtrace/tracer/option_test.go @@ -1206,11 +1206,14 @@ func TestWithLogStartup(t *testing.T) { func TestWithHeaderTags(t *testing.T) { t.Run("default-off", func(t *testing.T) { + defer globalconfig.ClearHeaderTags() assert := assert.New(t) newConfig() assert.Equal(0, globalconfig.HeaderTagsLen()) }) + t.Run("single-header", func(t *testing.T) { + defer globalconfig.ClearHeaderTags() assert := assert.New(t) header := "Header" newConfig(WithHeaderTags([]string{header})) @@ -1218,6 +1221,7 @@ func TestWithHeaderTags(t *testing.T) { }) t.Run("header-and-tag", func(t *testing.T) { + defer globalconfig.ClearHeaderTags() assert := assert.New(t) header := "Header" tag := "tag" @@ -1226,6 +1230,7 @@ func TestWithHeaderTags(t *testing.T) { }) t.Run("multi-header", func(t *testing.T) { + defer globalconfig.ClearHeaderTags() assert := assert.New(t) newConfig(WithHeaderTags([]string{"1header:1tag", "2header", "3header:3tag"})) assert.Equal("1tag", globalconfig.HeaderTag("1header")) @@ -1234,6 +1239,7 @@ func TestWithHeaderTags(t *testing.T) { }) t.Run("normalization", func(t *testing.T) { + defer globalconfig.ClearHeaderTags() assert := assert.New(t) newConfig(WithHeaderTags([]string{" h!e@a-d.e*r ", " 2header:t!a@g. "})) assert.Equal(ext.HTTPRequestHeaders+".h_e_a-d_e_r", globalconfig.HeaderTag("h!e@a-d.e*r")) @@ -1241,6 +1247,7 @@ func TestWithHeaderTags(t *testing.T) { }) t.Run("envvar-only", func(t *testing.T) { + defer globalconfig.ClearHeaderTags() os.Setenv("DD_TRACE_HEADER_TAGS", " 1header:1tag,2.h.e.a.d.e.r ") defer os.Unsetenv("DD_TRACE_HEADER_TAGS") @@ -1252,6 +1259,7 @@ func TestWithHeaderTags(t *testing.T) { }) t.Run("env-override", func(t *testing.T) { + defer globalconfig.ClearHeaderTags() assert := assert.New(t) os.Setenv("DD_TRACE_HEADER_TAGS", "unexpected") defer os.Unsetenv("DD_TRACE_HEADER_TAGS") @@ -1259,6 +1267,9 @@ func TestWithHeaderTags(t *testing.T) { assert.Equal(ext.HTTPRequestHeaders+".expected", globalconfig.HeaderTag("Expected")) assert.Equal(1, globalconfig.HeaderTagsLen()) }) + + // ensures we cleaned up global state correctly + assert.Equal(t, 0, globalconfig.HeaderTagsLen()) } func TestHostnameDisabled(t *testing.T) {