Skip to content

Commit 5abccfb

Browse files
committed
25. test: fix path separator issue in createTestTempDir
- Replace slashes with underscores in test names on all platforms - Fixes "pattern contains path separator" error in os.MkdirTemp - Issue was causing test failures on Linux CI for subtests - The slash replacement was only happening on Windows before Signed-off-by: Guillaume de Rouville <guillaume@dagger.io>
1 parent 9052fdf commit 5abccfb

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

environment/integration/helpers.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ func init() {
4040
func createTestTempDir(t *testing.T, prefix string) string {
4141
var dir string
4242
var err error
43-
43+
44+
// Get test name and replace slashes with underscores to avoid path separator issues
45+
testName := t.Name()
46+
testName = strings.ReplaceAll(testName, "/", "_")
47+
4448
if runtime.GOOS == "windows" {
4549
// On Windows, use a shorter base path to avoid path length issues
4650
// Generate a unique short name using last 8 chars of test name
47-
testName := t.Name()
48-
// Replace slashes with underscores to avoid path separator issues
49-
testName = strings.ReplaceAll(testName, "/", "_")
5051
if len(testName) > 8 {
5152
testName = testName[len(testName)-8:]
5253
}
@@ -59,9 +60,9 @@ func createTestTempDir(t *testing.T, prefix string) string {
5960
dir, err = os.MkdirTemp(tempRoot, prefix+testName+"-*")
6061
} else {
6162
// On other platforms, use the regular temp directory
62-
dir, err = os.MkdirTemp("", prefix+t.Name()+"-*")
63+
dir, err = os.MkdirTemp("", prefix+testName+"-*")
6364
}
64-
65+
6566
require.NoError(t, err, "Failed to create temp dir")
6667
t.Cleanup(func() {
6768
os.RemoveAll(dir)
@@ -127,6 +128,7 @@ type RepositorySetup func(t *testing.T, repoDir string)
127128

128129
// Common repository setups
129130
var (
131+
// SetupPythonRepo creates a Python project with main.py, requirements.txt, and .gitignore
130132
SetupPythonRepo = func(t *testing.T, repoDir string) {
131133
writeFile(t, repoDir, "main.py", "def main():\n print('Hello World')\n\nif __name__ == '__main__':\n main()\n")
132134
writeFile(t, repoDir, "requirements.txt", "requests==2.31.0\nnumpy==1.24.0\n")

0 commit comments

Comments
 (0)