From 60627df3deb144b1faefdf09e28ba3784e410950 Mon Sep 17 00:00:00 2001 From: Niels Henrik Hagen Date: Tue, 17 Dec 2024 14:58:37 +0100 Subject: [PATCH] fix: Use testhelpers to configure Datadog (#450) --- bootstrap_test.go | 8 ++------ internal/testhelpers/config.go | 3 +++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/bootstrap_test.go b/bootstrap_test.go index e4161c85..f379cd38 100644 --- a/bootstrap_test.go +++ b/bootstrap_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/coopnorge/go-datadog-lib/v2/internal" + "github.com/coopnorge/go-datadog-lib/v2/internal/testhelpers" "github.com/stretchr/testify/assert" ) @@ -22,12 +23,7 @@ func TestBootstrapDatadogDisabled(t *testing.T) { } func TestBootstrap(t *testing.T) { - t.Setenv(internal.DatadogDisable, "false") - t.Setenv(internal.DatadogAPMEndpoint, "/tmp") - t.Setenv(internal.DatadogDSDEndpoint, "unix:///tmp/") - t.Setenv(internal.DatadogEnvironment, "unittest") - t.Setenv(internal.DatadogService, "go-datadog-lib-unit-test") - t.Setenv(internal.DatadogVersion, "42345kjh435") + testhelpers.ConfigureDatadog(t) stop, err := Start(context.Background()) defer func() { diff --git a/internal/testhelpers/config.go b/internal/testhelpers/config.go index c9c4b31a..eb7d66d5 100644 --- a/internal/testhelpers/config.go +++ b/internal/testhelpers/config.go @@ -10,11 +10,14 @@ import ( // ConfigureDatadog prepares the environment for running tests func ConfigureDatadog(t *testing.T) { + t.Setenv(internal.DatadogDisable, "false") t.Setenv(internal.DatadogEnvironment, "unittest") t.Setenv(internal.DatadogService, "unittest-service") t.Setenv(internal.DatadogVersion, "v0.0.0") t.Setenv(internal.DatadogAPMEndpoint, "/dev/null") t.Setenv(internal.DatadogDSDEndpoint, "unix:///dev/null") + + // Called to ensure backwards compatibility cfg := config.LoadDatadogConfigFromEnvVars() err := cfg.Validate() assert.NoError(t, err)