src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/testutil/testdir_nonwindows_test.go (about) 1 //go:build !windows 2 3 package testutil 4 5 import ( 6 "os" 7 "testing" 8 ) 9 10 func TestApplyDir_CreatesFileWithPerm(t *testing.T) { 11 InTempDir(t) 12 13 ApplyDir(Dir{ 14 // For some unknown reason, termux on Android does not set the 15 // group and other permission bits correctly, so we use 700 here. 16 "a": File{0700, "a content"}, 17 }) 18 19 testFileContent(t, "a", "a content") 20 testFilePerm(t, "a", 0700) 21 } 22 23 func testFilePerm(t *testing.T, filename string, wantPerm os.FileMode) { 24 t.Helper() 25 info, err := os.Stat(filename) 26 if err != nil { 27 t.Errorf("Could not stat %v: %v", filename, err) 28 return 29 } 30 if perm := info.Mode().Perm(); perm != wantPerm { 31 t.Errorf("File %v has perm %o, want %o", filename, perm, wantPerm) 32 wd, err := os.Getwd() 33 if err == nil { 34 t.Logf("pwd is %v", wd) 35 } 36 } 37 }