|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed |
| 2 | +// under the Apache License Version 2.0. |
| 3 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 4 | +// Copyright 2016-present Datadog, Inc. |
| 5 | + |
| 6 | +//go:build test && !serverless |
| 7 | + |
| 8 | +package setup |
| 9 | + |
| 10 | +import ( |
| 11 | + "os" |
| 12 | + "path/filepath" |
| 13 | + "strings" |
| 14 | + "testing" |
| 15 | + |
| 16 | + "github.com/stretchr/testify/require" |
| 17 | + |
| 18 | + delegatedauthmock "github.com/DataDog/datadog-agent/comp/core/delegatedauth/mock" |
| 19 | + secretsmock "github.com/DataDog/datadog-agent/comp/core/secrets/mock" |
| 20 | + pkgconfigmodel "github.com/DataDog/datadog-agent/pkg/config/model" |
| 21 | +) |
| 22 | + |
| 23 | +// Regression test: the HOST_ETC repo dir rewrite used to run before the config was ready |
| 24 | +// (and before HOST_ETC auto-detection), so it silently never applied. |
| 25 | +func TestPostProcessSystemProbeRunsAfterConfigIsReady(t *testing.T) { |
| 26 | + origDatadog := Datadog().(pkgconfigmodel.BuildableConfig) |
| 27 | + origSystemProbe := SystemProbe().(pkgconfigmodel.BuildableConfig) |
| 28 | + t.Cleanup(func() { |
| 29 | + SetDatadog(origDatadog) // nolint: forbidigo // restoring the singleton after the test |
| 30 | + SetSystemProbe(origSystemProbe) // nolint: forbidigo // restoring the singleton after the test |
| 31 | + }) |
| 32 | + |
| 33 | + InitConfigObjects() |
| 34 | + |
| 35 | + t.Setenv("HOST_ETC", "/host/etc") |
| 36 | + |
| 37 | + configPath := filepath.Join(t.TempDir(), "empty_conf.yaml") |
| 38 | + require.NoError(t, os.WriteFile(configPath, nil, 0o600)) |
| 39 | + Datadog().(pkgconfigmodel.BuildableConfig).SetConfigFile(configPath) |
| 40 | + |
| 41 | + err := LoadDatadog(Datadog(), secretsmock.New(t), delegatedauthmock.New(t), nil) |
| 42 | + require.NoError(t, err) |
| 43 | + |
| 44 | + for _, name := range []string{ |
| 45 | + "system_probe_config.apt_config_dir", |
| 46 | + "system_probe_config.yum_repos_dir", |
| 47 | + "system_probe_config.zypper_repos_dir", |
| 48 | + } { |
| 49 | + val := SystemProbe().GetString(name) |
| 50 | + require.True(t, strings.HasPrefix(val, "/host/etc"), "expected %s to be rooted under HOST_ETC, got %q", name, val) |
| 51 | + } |
| 52 | +} |
0 commit comments