Skip to content

Commit

Permalink
[e2e] move CreateTestOutputDir to common
Browse files Browse the repository at this point in the history
Remove dependency from client to e2e
  • Loading branch information
pducolin committed Dec 27, 2024
1 parent bb552f8 commit 00093c0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion test/new-e2e/pkg/e2e/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 0 additions & 23 deletions test/new-e2e/pkg/e2e/suite_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
package e2e

import (
"os"
"path/filepath"
"strings"

"testing"
)

Expand All @@ -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: <root>/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
}
21 changes: 21 additions & 0 deletions test/new-e2e/pkg/utils/common/output_dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"
)

Expand Down Expand Up @@ -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: <root>/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
}
3 changes: 1 addition & 2 deletions test/new-e2e/pkg/utils/e2e/client/agent_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 00093c0

Please sign in to comment.