MCPcopy
hub / github.com/git-lfs/git-lfs / TestSetWriteFlag

Function TestSetWriteFlag

tools/filetools_test.go:286–329  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

284}
285
286func TestSetWriteFlag(t *testing.T) {
287 f, err := os.CreateTemp("", "lfstestwriteflag")
288 assert.Nil(t, err)
289 filename := f.Name()
290 defer os.Remove(filename)
291 f.Close()
292 // Set up with read/write bit for all but no execute
293 assert.Nil(t, os.Chmod(filename, 0666))
294
295 assert.Nil(t, SetFileWriteFlag(filename, false))
296 // should turn off all write
297 assert.EqualValues(t, 0444, getFileMode(filename))
298 assert.Nil(t, SetFileWriteFlag(filename, true))
299 // should only add back user write (on Mac/Linux)
300 if runtime.GOOS == "windows" {
301 assert.EqualValues(t, 0666, getFileMode(filename))
302 } else {
303 assert.EqualValues(t, 0644, getFileMode(filename))
304 }
305
306 // Can't run selective UGO tests on Windows as doesn't support separate roles
307 // Also Golang only supports read/write but not execute on Windows
308 if runtime.GOOS != "windows" {
309 // Set up with read/write/execute bit for all but no execute
310 assert.Nil(t, os.Chmod(filename, 0777))
311 assert.Nil(t, SetFileWriteFlag(filename, false))
312 // should turn off all write but not execute
313 assert.EqualValues(t, 0555, getFileMode(filename))
314 assert.Nil(t, SetFileWriteFlag(filename, true))
315 // should only add back user write (on Mac/Linux)
316 if runtime.GOOS == "windows" {
317 assert.EqualValues(t, 0777, getFileMode(filename))
318 } else {
319 assert.EqualValues(t, 0755, getFileMode(filename))
320 }
321
322 assert.Nil(t, os.Chmod(filename, 0440))
323 assert.Nil(t, SetFileWriteFlag(filename, false))
324 assert.EqualValues(t, 0440, getFileMode(filename))
325 assert.Nil(t, SetFileWriteFlag(filename, true))
326 // should only add back user write
327 assert.EqualValues(t, 0640, getFileMode(filename))
328 }
329}
330
331func TestExecutablePermissions(t *testing.T) {
332 assert.EqualValues(t, os.FileMode(0755), ExecutablePermissions(0644))

Callers

nothing calls this directly

Calls 5

SetFileWriteFlagFunction · 0.85
getFileModeFunction · 0.85
NameMethod · 0.65
CloseMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected