cleanup: getRootDir function
This commit is contained in:
parent
5651c852db
commit
0d8402be32
@ -217,12 +217,6 @@ func waitForPathNotExistWithTimeout(path string, timeout time.Duration) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getRootDir returns the root directory of the given directory
|
|
||||||
func getRootDir(path string) string {
|
|
||||||
parts := strings.Split(path, "/")
|
|
||||||
return parts[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
// removeEmptyDirs removes empty directories in the given directory dir until the parent directory parentDir
|
// removeEmptyDirs removes empty directories in the given directory dir until the parent directory parentDir
|
||||||
// It will remove all empty directories in the path from the given directory to the parent directory
|
// It will remove all empty directories in the path from the given directory to the parent directory
|
||||||
// It will not remove the parent directory parentDir
|
// It will not remove the parent directory parentDir
|
||||||
|
|||||||
@ -388,47 +388,6 @@ func TestWaitForPathNotExistWithTimeout(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetRootPath(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
desc string
|
|
||||||
dir string
|
|
||||||
expected string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
desc: "empty path",
|
|
||||||
dir: "",
|
|
||||||
expected: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "root path",
|
|
||||||
dir: "/",
|
|
||||||
expected: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "subdir path",
|
|
||||||
dir: "/subdir",
|
|
||||||
expected: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "subdir path without leading slash",
|
|
||||||
dir: "subdir",
|
|
||||||
expected: "subdir",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "multiple subdir path without leading slash",
|
|
||||||
dir: "subdir/subdir2",
|
|
||||||
expected: "subdir",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
result := getRootDir(test.dir)
|
|
||||||
if result != test.expected {
|
|
||||||
t.Errorf("Unexpected result: %s, expected: %s", result, test.expected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRemoveEmptyDirs(t *testing.T) {
|
func TestRemoveEmptyDirs(t *testing.T) {
|
||||||
parentDir, _ := os.Getwd()
|
parentDir, _ := os.Getwd()
|
||||||
emptyDirOneLevel, _ := getWorkDirPath("emptyDir1")
|
emptyDirOneLevel, _ := getWorkDirPath("emptyDir1")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user