test: more cases for os_file_is_readonly()

This commit is contained in:
Justin M. Keyes 2015-08-11 21:00:56 -04:00
parent 14d2a90db9
commit d5cd15e67f

View File

@ -314,10 +314,8 @@ describe('fs function', function()
end)
end
-- On Windows `os_fchown` always returns 0
-- because `uv_fs_chown` is no-op on this platform.
if (ffi.os == 'Windows' or ffi.C.geteuid() == 0) then
pending('skipped (os_fchown is no-op on Windows)', function() end)
pending('skipped (uv_fs_chown is no-op on Windows)', function() end)
else
it('returns nonzero if process has not enough permissions', function()
-- chown to root
@ -327,18 +325,51 @@ describe('fs function', function()
end)
describe('os_file_is_readonly', function()
it('returns true if the file is readonly', function()
-- pending('returns ? if the file does not exist', function() end)
-- pending('returns ? if the path is a directory', function() end)
-- pending('returns ? if the file is executable', function() end)
it('returns false if the file is non-read, non-write', function()
local perm = os_getperm('unit-test-directory/test.file')
perm = unset_bit(perm, ffi.C.kS_IWUSR)
perm = unset_bit(perm, ffi.C.kS_IWGRP)
perm = unset_bit(perm, ffi.C.kS_IWOTH)
perm = unset_bit(perm, ffi.C.kS_IRUSR)
perm = unset_bit(perm, ffi.C.kS_IRGRP)
perm = unset_bit(perm, ffi.C.kS_IROTH)
eq(OK, (os_setperm('unit-test-directory/test.file', perm)))
eq(1, os_file_is_writable('unit-test-directory/test.file'))
eq(false, os_file_is_readonly('unit-test-directory/test.file'))
end)
it('returns false if the file is write-only', function()
local perm = os_getperm('unit-test-directory/test.file')
perm = set_bit(perm, ffi.C.kS_IWUSR)
perm = set_bit(perm, ffi.C.kS_IWGRP)
perm = set_bit(perm, ffi.C.kS_IWOTH)
perm = unset_bit(perm, ffi.C.kS_IRUSR)
perm = unset_bit(perm, ffi.C.kS_IRGRP)
perm = unset_bit(perm, ffi.C.kS_IROTH)
eq(OK, (os_setperm('unit-test-directory/test.file', perm)))
eq(1, os_file_is_writable('unit-test-directory/test.file'))
eq(false, os_file_is_readonly('unit-test-directory/test.file'))
end)
it('returns true if the file is read-only', function()
local perm = os_getperm('unit-test-directory/test.file')
local perm_orig = perm
perm = unset_bit(perm, ffi.C.kS_IWUSR)
perm = unset_bit(perm, ffi.C.kS_IWGRP)
perm = unset_bit(perm, ffi.C.kS_IWOTH)
eq(OK, (os_setperm('unit-test-directory/test.file', perm)))
eq(true, os_file_is_readonly('unit-test-directory/test.file'))
eq(OK, (os_setperm('unit-test-directory/test.file', perm_orig)))
end)
it('returns false if the file is writable', function()
it('returns false if the file is read-write', function()
eq(false, os_file_is_readonly('unit-test-directory/test.file'))
end)
end)