MCPcopy
hub / github.com/syncthing/syncthing / TestChownFile

Function TestChownFile

lib/fs/basicfs_test.go:62–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

60}
61
62func TestChownFile(t *testing.T) {
63 if build.IsWindows {
64 t.Skip("Not supported on Windows")
65 return
66 }
67 if os.Getuid() != 0 {
68 // We are not root. No expectation of being able to chown. Our tests
69 // typically don't run with CAP_FOWNER.
70 t.Skip("Test not possible")
71 return
72 }
73
74 fs, dir := setup(t)
75 path := filepath.Join(dir, "file")
76
77 defer os.Chmod(path, 0o666)
78
79 fd, err := os.Create(path)
80 if err != nil {
81 t.Error("Unexpected error:", err)
82 }
83 fd.Close()
84
85 _, err = fs.Lstat("file")
86 if err != nil {
87 t.Error("Unexpected error:", err)
88 }
89
90 newUID := 1000 + rand.Intn(30000)
91 newGID := 1000 + rand.Intn(30000)
92
93 if err := fs.Lchown("file", strconv.Itoa(newUID), strconv.Itoa(newGID)); err != nil {
94 t.Error("Unexpected error:", err)
95 }
96
97 info, err := fs.Lstat("file")
98 if err != nil {
99 t.Error("Unexpected error:", err)
100 }
101 if info.Owner() != newUID {
102 t.Errorf("Incorrect owner, expected %d but got %d", newUID, info.Owner())
103 }
104 if info.Group() != newGID {
105 t.Errorf("Incorrect group, expected %d but got %d", newGID, info.Group())
106 }
107}
108
109func TestChmodDir(t *testing.T) {
110 fs, dir := setup(t)

Callers

nothing calls this directly

Calls 10

IntnFunction · 0.92
setupFunction · 0.85
ChmodMethod · 0.65
CreateMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65
LstatMethod · 0.65
LchownMethod · 0.65
OwnerMethod · 0.65
GroupMethod · 0.65

Tested by

no test coverage detected