MCPcopy
hub / github.com/u-root/u-root / TestChmodSimple

Function TestChmodSimple

cmds/chmod/chmod_test.go:26–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24}
25
26func TestChmodSimple(t *testing.T) {
27 // Temporary directories.
28 tempDir, err := ioutil.TempDir("", "TestChmodSimple")
29 if err != nil {
30 t.Fatalf("cannot create temporary directory: %v", err)
31 }
32 defer os.RemoveAll(tempDir)
33
34 f, err := ioutil.TempFile(tempDir, "BLAH1")
35 if err != nil {
36 t.Fatalf("cannot create temporary file: %v", err)
37 }
38 defer f.Close()
39
40 for _, perm := range []os.FileMode{0777, 0644} {
41 // Set permissions using chmod.
42 c := testutil.Command(t, fmt.Sprintf("%0o", perm), f.Name())
43 c.Run()
44
45 // Check that it worked.
46 info, err := os.Stat(f.Name())
47 if err != nil {
48 t.Fatalf("stat(%q) failed: %v", f.Name(), err)
49 }
50 if got := info.Mode().Perm(); got != perm {
51 t.Errorf("Wrong file permissions on %q: got %0o, want %0o", f.Name(), got, perm)
52 }
53 }
54}
55
56func checkPath(t *testing.T, path string, want os.FileMode) {
57 info, err := os.Stat(path)

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.65
CommandMethod · 0.65
NameMethod · 0.65
ErrorfMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…