fix parent directory

This commit is contained in:
Priya Wadhwa
2018-04-25 12:59:18 -07:00
parent a211c1ec71
commit 946b11b894
2 changed files with 5 additions and 8 deletions
+2 -2
View File
@@ -148,8 +148,8 @@ func ParentDirectories(path string) []string {
dirs := strings.Split(path, "/")
dirPath := constants.RootDir
var paths []string
for _, dir := range dirs {
if dir == "" {
for index, dir := range dirs {
if dir == "" || index == (len(dirs)-1) {
continue
}
dirPath = filepath.Join(dirPath, dir)
+3 -6
View File
@@ -144,15 +144,12 @@ func Test_ParentDirectories(t *testing.T) {
expected: []string{
"/path",
"/path/to",
"/path/to/dir",
},
},
{
name: "current directory",
path: ".",
expected: []string{
"/",
},
name: "current directory",
path: ".",
expected: nil,
},
}