Fix sorting of parent directories.

This refactoring reversed the order of the "ParentDirectories" function: ffc372a63b (diff-d36eb675aa49a7b471e3a2be77005b18R465)

As a side-effect, parent directories weren't added in lexicographical
order, which broke some tests. We now ensure in unit test that the order
of the ParentDirectories function is stable.
This commit is contained in:
Gilbert Gilb's 2020-03-31 20:12:00 +02:00
parent fd8a2d6dd8
commit 14170aa455
2 changed files with 2 additions and 4 deletions

View File

@ -468,10 +468,10 @@ func ParentDirectories(path string) []string {
}
dir, _ = filepath.Split(dir)
dir = filepath.Clean(dir)
paths = append(paths, dir)
paths = append([]string{dir}, paths...)
}
if len(paths) == 0 {
paths = append(paths, config.RootDir)
paths = []string{config.RootDir}
}
return paths
}

View File

@ -213,8 +213,6 @@ func Test_ParentDirectories(t *testing.T) {
defer func() { config.RootDir = original }()
config.RootDir = tt.rootDir
actual := ParentDirectories(tt.path)
sort.Strings(actual)
sort.Strings(tt.expected)
testutil.CheckErrorAndDeepEqual(t, false, nil, tt.expected, actual)
})