Merged master, fixed merge conflict

This commit is contained in:
Priya Wadhwa
2018-05-09 13:50:33 -07:00
22 changed files with 616 additions and 50 deletions
+17
View File
@@ -326,6 +326,23 @@ func Files(root string) ([]string, error) {
return files, err
}
// ParentDirectories returns a list of paths to all parent directories
// Ex. /some/temp/dir -> [/some, /some/temp, /some/temp/dir]
func ParentDirectories(path string) []string {
path = filepath.Clean(path)
dirs := strings.Split(path, "/")
dirPath := constants.RootDir
var paths []string
for index, dir := range dirs {
if dir == "" || index == (len(dirs)-1) {
continue
}
dirPath = filepath.Join(dirPath, dir)
paths = append(paths, dirPath)
}
return paths
}
// FilepathExists returns true if the path exists
func FilepathExists(path string) bool {
_, err := os.Lstat(path)
+29
View File
@@ -132,6 +132,35 @@ func Test_RelativeFiles(t *testing.T) {
}
}
func Test_ParentDirectories(t *testing.T) {
tests := []struct {
name string
path string
expected []string
}{
{
name: "regular path",
path: "/path/to/dir",
expected: []string{
"/path",
"/path/to",
},
},
{
name: "current directory",
path: ".",
expected: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := ParentDirectories(tt.path)
testutil.CheckErrorAndDeepEqual(t, false, nil, tt.expected, actual)
})
}
}
func Test_checkWhiteouts(t *testing.T) {
type args struct {
path string