From 379584b8e3662b83eb62066eece4ea4e96243c09 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Santos Date: Fri, 10 Jan 2025 15:51:26 +0000 Subject: [PATCH] Fix fx test imports --- comp/core/tagger/mock/fake_tagger.go | 2 +- comp/core/tagger/mock/mock.go | 10 +++++++++- comp/otelcol/otlp/collector_test.go | 4 +++- comp/otelcol/otlp/config_test.go | 17 +++++++++++++---- comp/trace/config/config_test.go | 2 +- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/comp/core/tagger/mock/fake_tagger.go b/comp/core/tagger/mock/fake_tagger.go index 1a7b735ebb0209..c85897bd273d81 100644 --- a/comp/core/tagger/mock/fake_tagger.go +++ b/comp/core/tagger/mock/fake_tagger.go @@ -44,7 +44,7 @@ type Dependencies struct { // Provides is a struct containing the mock type Provides struct { - Comp tagger.Component + Comp Mock } // New instantiates a new fake tagger diff --git a/comp/core/tagger/mock/mock.go b/comp/core/tagger/mock/mock.go index 26b9781c871ec7..cd596dfd7346fe 100644 --- a/comp/core/tagger/mock/mock.go +++ b/comp/core/tagger/mock/mock.go @@ -11,6 +11,10 @@ package mock import ( "testing" + "go.uber.org/fx" + + "github.com/DataDog/datadog-agent/comp/core/config" + tagger "github.com/DataDog/datadog-agent/comp/core/tagger/def" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) @@ -23,5 +27,9 @@ func Module() fxutil.Module { // SetupFakeTagger calls fxutil.Test to create a mock tagger for testing func SetupFakeTagger(t testing.TB) Mock { - return fxutil.Test[Mock](t, Module()) + return fxutil.Test[Mock](t, + config.MockModule(), + fx.Provide(func(mock Mock) tagger.Component { return mock }), + Module(), + ) } diff --git a/comp/otelcol/otlp/collector_test.go b/comp/otelcol/otlp/collector_test.go index 6134d8a6a9a47f..070178f8ef3a18 100644 --- a/comp/otelcol/otlp/collector_test.go +++ b/comp/otelcol/otlp/collector_test.go @@ -78,6 +78,8 @@ func TestStartPipeline(t *testing.T) { } func TestStartPipelineFromConfig(t *testing.T) { + fakeTagger := mock.SetupFakeTagger(t) + pkgconfigsetup.Datadog().SetWithoutSource("hostname", "otlp-testhostname") defer pkgconfigsetup.Datadog().SetWithoutSource("hostname", "") @@ -101,7 +103,7 @@ func TestStartPipelineFromConfig(t *testing.T) { t.Run(testInstance.path, func(t *testing.T) { cfg, err := testutil.LoadConfig(t, "./testdata/"+testInstance.path) require.NoError(t, err) - pcfg, err := FromAgentConfig(cfg) + pcfg, err := FromAgentConfig(cfg, fakeTagger) require.NoError(t, err) if testInstance.err == "" { AssertSucessfulRun(t, pcfg) diff --git a/comp/otelcol/otlp/config_test.go b/comp/otelcol/otlp/config_test.go index 64ba24ff772e0f..7929e3fcb9aae1 100644 --- a/comp/otelcol/otlp/config_test.go +++ b/comp/otelcol/otlp/config_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/DataDog/datadog-agent/comp/core/tagger/mock" "github.com/DataDog/datadog-agent/comp/otelcol/otlp/configcheck" "github.com/DataDog/datadog-agent/comp/otelcol/otlp/testutil" ) @@ -46,6 +47,8 @@ func TestIsEnabledEnv(t *testing.T) { } func TestFromAgentConfigReceiver(t *testing.T) { + fakeTagger := mock.SetupFakeTagger(t) + tests := []struct { path string cfg PipelineConfig @@ -189,7 +192,7 @@ func TestFromAgentConfigReceiver(t *testing.T) { t.Run(testInstance.path, func(t *testing.T) { cfg, err := testutil.LoadConfig(t, "./testdata/"+testInstance.path) require.NoError(t, err) - pcfg, err := FromAgentConfig(cfg) + pcfg, err := FromAgentConfig(cfg, fakeTagger) if err != nil || testInstance.err != "" { assert.Equal(t, testInstance.err, err.Error()) return @@ -202,6 +205,8 @@ func TestFromAgentConfigReceiver(t *testing.T) { } func TestFromEnvironmentVariables(t *testing.T) { + fakeTagger := mock.SetupFakeTagger(t) + tests := []struct { name string env map[string]string @@ -458,7 +463,7 @@ func TestFromEnvironmentVariables(t *testing.T) { } cfg, err := testutil.LoadConfig(t, "./testdata/empty.yaml") require.NoError(t, err) - pcfg, err := FromAgentConfig(cfg) + pcfg, err := FromAgentConfig(cfg, fakeTagger) if err != nil || testInstance.err != "" { assert.Equal(t, testInstance.err, err.Error()) return @@ -471,6 +476,8 @@ func TestFromEnvironmentVariables(t *testing.T) { } func TestFromAgentConfigMetrics(t *testing.T) { + fakeTagger := mock.SetupFakeTagger(t) + tests := []struct { path string cfg PipelineConfig @@ -510,7 +517,7 @@ func TestFromAgentConfigMetrics(t *testing.T) { t.Run(testInstance.path, func(t *testing.T) { cfg, err := testutil.LoadConfig(t, "./testdata/"+testInstance.path) require.NoError(t, err) - pcfg, err := FromAgentConfig(cfg) + pcfg, err := FromAgentConfig(cfg, fakeTagger) if err != nil || testInstance.err != "" { assert.Equal(t, testInstance.err, err.Error()) return @@ -523,6 +530,8 @@ func TestFromAgentConfigMetrics(t *testing.T) { } func TestFromAgentConfigDebug(t *testing.T) { + fakeTagger := mock.SetupFakeTagger(t) + tests := []struct { path string cfg PipelineConfig @@ -606,7 +615,7 @@ func TestFromAgentConfigDebug(t *testing.T) { t.Run(testInstance.path, func(t *testing.T) { cfg, err := testutil.LoadConfig(t, "./testdata/"+testInstance.path) require.NoError(t, err) - pcfg, err := FromAgentConfig(cfg) + pcfg, err := FromAgentConfig(cfg, fakeTagger) if err != nil || testInstance.err != "" { assert.Equal(t, testInstance.err, err.Error()) return diff --git a/comp/trace/config/config_test.go b/comp/trace/config/config_test.go index 9706e2c784f4ca..ec05be92044a86 100644 --- a/comp/trace/config/config_test.go +++ b/comp/trace/config/config_test.go @@ -2304,7 +2304,7 @@ func buildConfigComponent(t *testing.T, setHostnameInConfig bool, coreConfigOpti } taggerComponent := fxutil.Test[taggermock.Mock](t, - fx.Replace(coreConfig), + corecomp.MockModule(), taggermock.Module(), )