go(algo/util): add createPath func
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
babbd4201e
commit
b9a4ff3192
15
algo/util.go
15
algo/util.go
@ -28,3 +28,18 @@ func createFolder(path string) error {
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// createPath creates all folders in the provided path, if they don't already
|
||||||
|
// exist.
|
||||||
|
func createPath(path string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {
|
||||||
|
err = os.MkdirAll(path, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@ -22,3 +22,18 @@ func TestCreateFolder(t *testing.T) {
|
|||||||
|
|
||||||
os.RemoveAll(testPath)
|
os.RemoveAll(testPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint: ifshort
|
||||||
|
func TestCreatePath(t *testing.T) {
|
||||||
|
// let's assume this, too, will never exist in a clean project...
|
||||||
|
testPath := "whatever-path/whatever-subpath/subsubpath"
|
||||||
|
got := createPath(testPath)
|
||||||
|
|
||||||
|
var want error
|
||||||
|
|
||||||
|
if want != got {
|
||||||
|
t.Errorf("issue creating folders in path, testPath: %q, full cmd: %q", testPath, got.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
os.RemoveAll(testPath)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user