From 49232cbd90a674fd0301131fea0eaeedeb16750a Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Tue, 24 May 2022 16:43:27 +0100 Subject: [PATCH] Fix tests failing in Ubuntu Some test cases rely on checksum to match in order to pass. Those checksums were calculated based on file headers which contain their file modes. In Ubuntu, the umask is set to 002 by default, resulting in the tests files having different permissions then when the same files are cloned on another Linux machine with umask set to 022. This change ensures that the files are always set (to 0644 and the directories to 0755) before running the aforementioned tests. Signed-off-by: Paulo Gomes --- controllers/gitrepository_controller_test.go | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/controllers/gitrepository_controller_test.go b/controllers/gitrepository_controller_test.go index fd78abcd..50a9463f 100644 --- a/controllers/gitrepository_controller_test.go +++ b/controllers/gitrepository_controller_test.go @@ -919,6 +919,8 @@ func TestGitRepositoryReconciler_reconcileArtifact(t *testing.T) { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) + resetChmod(tt.dir, 0o755, 0o644) + r := &GitRepositoryReconciler{ EventRecorder: record.NewFakeRecorder(32), Storage: testStorage, @@ -2142,3 +2144,24 @@ func TestGitRepositoryReconciler_calculateContentConfigChecksum(t *testing.T) { artifactCsumModChecksum := r.calculateContentConfigChecksum(obj, artifacts) g.Expect(artifactModChecksum).ToNot(Equal(artifactCsumModChecksum)) } + +func resetChmod(path string, dirMode os.FileMode, fileMode os.FileMode) error { + err := filepath.Walk(path, + func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if info.IsDir() && info.Mode() != dirMode { + os.Chmod(path, dirMode) + } else if !info.IsDir() && info.Mode() != fileMode { + os.Chmod(path, fileMode) + } + return nil + }) + if err != nil { + return fmt.Errorf("cannot reset file permissions: %v", err) + } + + return nil +}