diff --git a/utils/fileutils.go b/utils/fileutils.go index b21cc9be..61d766ac 100644 --- a/utils/fileutils.go +++ b/utils/fileutils.go @@ -273,7 +273,7 @@ func GetFileContentAndInfo(filePath string) (fileContent []byte, fileInfo os.Fil func CreateTempDir() (string, error) { tempDirBase := os.TempDir() timestamp := strconv.FormatInt(time.Now().Unix(), 10) - return os.MkdirTemp(tempDirBase, tempDirPrefix+timestamp+"-") + return os.MkdirTemp(tempDirBase, tempDirPrefix+timestamp+"-*") } func RemoveTempDir(dirPath string) error { diff --git a/utils/fileutils_test.go b/utils/fileutils_test.go index 3cede3c2..556af447 100644 --- a/utils/fileutils_test.go +++ b/utils/fileutils_test.go @@ -54,3 +54,19 @@ func TestReadNLines(t *testing.T) { assert.True(t, strings.HasPrefix(lines[1], "781")) assert.True(t, strings.HasSuffix(lines[1], ":true}}}")) } + +func TestCreateTempDir(t *testing.T) { + tempDir, err := CreateTempDir() + assert.NoError(t, err) + + _, err = os.Stat(tempDir) + assert.NotErrorIs(t, err, os.ErrNotExist) + + defer func() { + // Check that a timestamp can be extracted from the temp dir name + _, err = extractTimestamp(tempDir) + assert.NoError(t, err) + + assert.NoError(t, os.RemoveAll(tempDir)) + }() +}