testdir_nonwindows_test.go 786 B

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