From 14170aa455fd16ed606bb3afda2ab1c5847e3d90 Mon Sep 17 00:00:00 2001 From: Gilbert Gilb's Date: Tue, 31 Mar 2020 20:12:00 +0200 Subject: [PATCH] Fix sorting of parent directories. This refactoring reversed the order of the "ParentDirectories" function: https://github.com/GoogleContainerTools/kaniko/pull/1155/commits/ffc372a63bca75e5b7c680c981d2444fc4017897#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. --- pkg/util/fs_util.go | 4 ++-- pkg/util/fs_util_test.go | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index a5ecaab1b..230d87669 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -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 } diff --git a/pkg/util/fs_util_test.go b/pkg/util/fs_util_test.go index b560330b2..5ba37fef9 100644 --- a/pkg/util/fs_util_test.go +++ b/pkg/util/fs_util_test.go @@ -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) })