File: testdir_nonwindows_test.go

package info (click to toggle)
elvish 0.21.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,372 kB
  • sloc: javascript: 236; sh: 130; python: 104; makefile: 88; xml: 9
file content (37 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//go:build !windows

package testutil

import (
	"os"
	"testing"
)

func TestApplyDir_CreatesFileWithPerm(t *testing.T) {
	InTempDir(t)

	ApplyDir(Dir{
		// For some unknown reason, termux on Android does not set the
		// group and other permission bits correctly, so we use 700 here.
		"a": File{0700, "a content"},
	})

	testFileContent(t, "a", "a content")
	testFilePerm(t, "a", 0700)
}

func testFilePerm(t *testing.T, filename string, wantPerm os.FileMode) {
	t.Helper()
	info, err := os.Stat(filename)
	if err != nil {
		t.Errorf("Could not stat %v: %v", filename, err)
		return
	}
	if perm := info.Mode().Perm(); perm != wantPerm {
		t.Errorf("File %v has perm %o, want %o", filename, perm, wantPerm)
		wd, err := os.Getwd()
		if err == nil {
			t.Logf("pwd is %v", wd)
		}
	}
}