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