Skip to content

Commit 015d5a6

Browse files
authored
Merge pull request #440 from michelgrootjans/fix-missing-directory
Fix missing directory
2 parents f525a30 + b630db9 commit 015d5a6

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

mob_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,26 +2111,27 @@ func createFileInPath(t *testing.T, path, filename, content string) (pathToFile
21112111
}
21122112

21132113
func createExecutableFileInPath(t *testing.T, path, filename, content string) (pathToFile string) {
2114-
contentAsBytes := []byte(content)
2114+
ensureDirectoryExists(t, path)
2115+
21152116
pathToFile = path + "/" + filename
2117+
contentAsBytes := []byte(content)
21162118
err := os.WriteFile(pathToFile, contentAsBytes, 0755)
21172119
if err != nil {
21182120
failWithFailure(t, "creating file "+filename+" with content "+content, "error")
21192121
}
21202122
return
21212123
}
21222124

2123-
func createDirectory(t *testing.T, directory string) (pathToFile string) {
2124-
return createDirectoryInPath(t, workingDir, directory)
2125+
func createDirectory(t *testing.T, directory string) (pathToDirectory string) {
2126+
return ensureDirectoryExists(t, workingDir+"/"+directory)
21252127
}
21262128

2127-
func createDirectoryInPath(t *testing.T, path, directory string) (pathToFile string) {
2128-
pathToFile = path + "/" + directory
2129-
err := os.Mkdir(pathToFile, 0755)
2129+
func ensureDirectoryExists(t *testing.T, path string) (pathToDirectory string) {
2130+
err := os.MkdirAll(path, 0755)
21302131
if err != nil {
2131-
failWithFailure(t, "creating directory "+pathToFile, "error")
2132+
failWithFailure(t, "creating folder "+path, "error")
21322133
}
2133-
return
2134+
return path
21342135
}
21352136

21362137
func removeFile(t *testing.T, path string) {

0 commit comments

Comments
 (0)