Skip to content

Commit

Permalink
git: add file mode verification to tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Jul 3, 2024
1 parent 6493fd0 commit 899cac1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion source/git/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,21 @@ func testFetchByTag(t *testing.T, tag, expectedCommitSubject string, isAnnotated
require.NoError(t, err)
defer lm.Unmount()

st, err := os.Lstat(filepath.Join(dir, "subdir"))
require.NoError(t, err)

require.True(t, st.IsDir())
require.Equal(t, strconv.FormatInt(0755, 8), strconv.FormatInt(int64(st.Mode()&os.ModePerm), 8))

dt, err := os.ReadFile(filepath.Join(dir, "def"))
require.NoError(t, err)
require.Equal(t, "bar\n", string(dt))

st, err = os.Lstat(filepath.Join(dir, "def"))
require.NoError(t, err)

require.Equal(t, strconv.FormatInt(0644, 8), strconv.FormatInt(int64(st.Mode()&os.ModePerm), 8))

dt, err = os.ReadFile(filepath.Join(dir, "foo13"))
if hasFoo13File {
require.NoError(t, err)
Expand Down Expand Up @@ -692,7 +703,9 @@ func setupGitRepo(t *testing.T) gitRepoFixture {
"git commit -m initial",
"git tag --no-sign a/v1.2.3",
"echo bar > def",
"git add def",
"mkdir subdir",
"echo subcontents > subdir/subfile",
"git add def subdir",
"git commit -m second",
"git tag -a -m \"this is an annotated tag\" v1.2.3",
"echo foo > bar",
Expand Down
11 changes: 11 additions & 0 deletions source/git/source_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !windows
// +build !windows

package git

import "syscall"

func init() {
// Reset umask to zero to match buildkitd and to make sure the tests do not rely on standard umask from the host.
syscall.Umask(0)
}

0 comments on commit 899cac1

Please sign in to comment.