Skip to content

Commit 49232cb

Browse files
author
Paulo Gomes
committed
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 <[email protected]>
1 parent 6e768b3 commit 49232cb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

controllers/gitrepository_controller_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,8 @@ func TestGitRepositoryReconciler_reconcileArtifact(t *testing.T) {
919919
t.Run(tt.name, func(t *testing.T) {
920920
g := NewWithT(t)
921921

922+
resetChmod(tt.dir, 0o755, 0o644)
923+
922924
r := &GitRepositoryReconciler{
923925
EventRecorder: record.NewFakeRecorder(32),
924926
Storage: testStorage,
@@ -2142,3 +2144,24 @@ func TestGitRepositoryReconciler_calculateContentConfigChecksum(t *testing.T) {
21422144
artifactCsumModChecksum := r.calculateContentConfigChecksum(obj, artifacts)
21432145
g.Expect(artifactModChecksum).ToNot(Equal(artifactCsumModChecksum))
21442146
}
2147+
2148+
func resetChmod(path string, dirMode os.FileMode, fileMode os.FileMode) error {
2149+
err := filepath.Walk(path,
2150+
func(path string, info os.FileInfo, err error) error {
2151+
if err != nil {
2152+
return err
2153+
}
2154+
2155+
if info.IsDir() && info.Mode() != dirMode {
2156+
os.Chmod(path, dirMode)
2157+
} else if !info.IsDir() && info.Mode() != fileMode {
2158+
os.Chmod(path, fileMode)
2159+
}
2160+
return nil
2161+
})
2162+
if err != nil {
2163+
return fmt.Errorf("cannot reset file permissions: %v", err)
2164+
}
2165+
2166+
return nil
2167+
}

0 commit comments

Comments
 (0)