Skip to content

Commit

Permalink
Fix fx test imports
Browse files Browse the repository at this point in the history
  • Loading branch information
gabedos committed Jan 10, 2025
1 parent c4a12d9 commit 89c1a19
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
2 changes: 0 additions & 2 deletions comp/core/tagger/collectors/workloadmeta_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const (
processSource = workloadmetaCollectorName + "-" + string(workloadmeta.KindProcess)
kubeMetadataSource = workloadmetaCollectorName + "-" + string(workloadmeta.KindKubernetesMetadata)
deploymentSource = workloadmetaCollectorName + "-" + string(workloadmeta.KindKubernetesDeployment)

clusterTagNamePrefix = "kube_cluster_name"
)

// CollectorPriorities holds collector priorities
Expand Down
2 changes: 1 addition & 1 deletion comp/core/tagger/mock/fake_tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion comp/core/tagger/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package mock
import (
"testing"

"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
)

Expand All @@ -23,5 +24,8 @@ 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(),
Module(),
)
}
1 change: 0 additions & 1 deletion comp/dogstatsd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ func newServerCompat(cfg model.Reader, log log.Component, capture replay.Compone
// if the server is running in a context where static tags are required, add those
// to extraTags.
staticTags, err := tagger.GlobalTags(types.LowCardinality)
log.Errorf("GABE: got staticTags from tagger: %v", staticTags)
if err != nil {
log.Errorf("Dogstatsd: unable to get static tags: %s", err)
}
Expand Down
4 changes: 3 additions & 1 deletion comp/otelcol/otlp/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")

Expand All @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions comp/otelcol/otlp/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -46,6 +47,8 @@ func TestIsEnabledEnv(t *testing.T) {
}

func TestFromAgentConfigReceiver(t *testing.T) {
fakeTagger := mock.SetupFakeTagger(t)

tests := []struct {
path string
cfg PipelineConfig
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -471,6 +476,8 @@ func TestFromEnvironmentVariables(t *testing.T) {
}

func TestFromAgentConfigMetrics(t *testing.T) {
fakeTagger := mock.SetupFakeTagger(t)

tests := []struct {
path string
cfg PipelineConfig
Expand Down Expand Up @@ -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
Expand All @@ -523,6 +530,8 @@ func TestFromAgentConfigMetrics(t *testing.T) {
}

func TestFromAgentConfigDebug(t *testing.T) {
fakeTagger := mock.SetupFakeTagger(t)

tests := []struct {
path string
cfg PipelineConfig
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion comp/trace/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)

Expand Down

0 comments on commit 89c1a19

Please sign in to comment.