Skip to content

Commit 899cac1

Browse files
committed
git: add file mode verification to tests
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 6493fd0 commit 899cac1

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

source/git/source_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,21 @@ func testFetchByTag(t *testing.T, tag, expectedCommitSubject string, isAnnotated
373373
require.NoError(t, err)
374374
defer lm.Unmount()
375375

376+
st, err := os.Lstat(filepath.Join(dir, "subdir"))
377+
require.NoError(t, err)
378+
379+
require.True(t, st.IsDir())
380+
require.Equal(t, strconv.FormatInt(0755, 8), strconv.FormatInt(int64(st.Mode()&os.ModePerm), 8))
381+
376382
dt, err := os.ReadFile(filepath.Join(dir, "def"))
377383
require.NoError(t, err)
378384
require.Equal(t, "bar\n", string(dt))
379385

386+
st, err = os.Lstat(filepath.Join(dir, "def"))
387+
require.NoError(t, err)
388+
389+
require.Equal(t, strconv.FormatInt(0644, 8), strconv.FormatInt(int64(st.Mode()&os.ModePerm), 8))
390+
380391
dt, err = os.ReadFile(filepath.Join(dir, "foo13"))
381392
if hasFoo13File {
382393
require.NoError(t, err)
@@ -692,7 +703,9 @@ func setupGitRepo(t *testing.T) gitRepoFixture {
692703
"git commit -m initial",
693704
"git tag --no-sign a/v1.2.3",
694705
"echo bar > def",
695-
"git add def",
706+
"mkdir subdir",
707+
"echo subcontents > subdir/subfile",
708+
"git add def subdir",
696709
"git commit -m second",
697710
"git tag -a -m \"this is an annotated tag\" v1.2.3",
698711
"echo foo > bar",

source/git/source_unix_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package git
5+
6+
import "syscall"
7+
8+
func init() {
9+
// Reset umask to zero to match buildkitd and to make sure the tests do not rely on standard umask from the host.
10+
syscall.Umask(0)
11+
}

0 commit comments

Comments
 (0)