diff --git a/test/new-e2e/pkg/e2e/suite.go b/test/new-e2e/pkg/e2e/suite.go index 859c89f1917e0..2053b9a3bf89f 100644 --- a/test/new-e2e/pkg/e2e/suite.go +++ b/test/new-e2e/pkg/e2e/suite.go @@ -632,7 +632,7 @@ func (bs *BaseSuite[Env]) CreateTestOutputDir() (string, error) { if err != nil { return "", err } - return CreateTestOutputDir(root, bs.T()) + return common.CreateTestOutputDir(root, bs.T()) } // Run is a helper function to run a test suite. diff --git a/test/new-e2e/pkg/e2e/suite_utils.go b/test/new-e2e/pkg/e2e/suite_utils.go index 5aeca99fefd9a..839e6583c3fbe 100644 --- a/test/new-e2e/pkg/e2e/suite_utils.go +++ b/test/new-e2e/pkg/e2e/suite_utils.go @@ -6,10 +6,6 @@ package e2e import ( - "os" - "path/filepath" - "strings" - "testing" ) @@ -26,22 +22,3 @@ func (tl testLogger) Write(p []byte) (n int, err error) { tl.t.Log(string(p)) return len(p), nil } - -// CreateTestOutputDir creates a directory for a specific test that can be used to store output files and artifacts. -// The test name is used in the directory name, and invalid characters are replaced with underscores. -// -// Example: -// - test name: TestInstallSuite/TestInstall/install_version=7.50.0 -// - output directory: /TestInstallSuite/TestInstall/install_version_7_50_0 -func CreateTestOutputDir(root string, t *testing.T) (string, error) { - // https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words - invalidPathChars := strings.Join([]string{"?", "%", "*", ":", "|", "\"", "<", ">", ".", ",", ";", "="}, "") - - testPart := strings.ReplaceAll(t.Name(), invalidPathChars, "_") - path := filepath.Join(root, testPart) - err := os.MkdirAll(path, 0755) - if err != nil { - return "", err - } - return path, nil -} diff --git a/test/new-e2e/pkg/utils/common/output_dirs.go b/test/new-e2e/pkg/utils/common/output_dirs.go index f50dffa04f9e1..00182ea55b527 100644 --- a/test/new-e2e/pkg/utils/common/output_dirs.go +++ b/test/new-e2e/pkg/utils/common/output_dirs.go @@ -9,6 +9,8 @@ import ( "fmt" "os" "path/filepath" + "strings" + "testing" "time" ) @@ -56,3 +58,22 @@ func CreateTestSessionOutputDir(outputRoot string) (string, error) { } return outputRoot, nil } + +// CreateTestOutputDir creates a local directory for a specific test that can be used to store output files and artifacts. +// The test name is used in the directory name, and invalid characters are replaced with underscores. +// +// Example: +// - test name: TestInstallSuite/TestInstall/install_version=7.50.0 +// - output directory: /TestInstallSuite/TestInstall/install_version_7_50_0 +func CreateTestOutputDir(root string, t *testing.T) (string, error) { + // https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words + invalidPathChars := strings.Join([]string{"?", "%", "*", ":", "|", "\"", "<", ">", ".", ",", ";", "="}, "") + + testPart := strings.ReplaceAll(t.Name(), invalidPathChars, "_") + path := filepath.Join(root, testPart) + err := os.MkdirAll(path, 0755) + if err != nil { + return "", err + } + return path, nil +} diff --git a/test/new-e2e/pkg/utils/e2e/client/agent_client.go b/test/new-e2e/pkg/utils/e2e/client/agent_client.go index 86c9f4ed21477..41700d4b548ae 100644 --- a/test/new-e2e/pkg/utils/e2e/client/agent_client.go +++ b/test/new-e2e/pkg/utils/e2e/client/agent_client.go @@ -19,7 +19,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/agentclient" @@ -206,7 +205,7 @@ func generateAndDownloadFlare(t *testing.T, commandRunner *agentCommandRunner, h if err != nil { return fmt.Errorf("could not get test session output directory: %w", err) } - outputDir, err := e2e.CreateTestOutputDir(root, t) + outputDir, err := common.CreateTestOutputDir(root, t) if err != nil { return fmt.Errorf("could not get output directory: %w", err) }