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