TESTS: add deleteDirSpec

This commit is contained in:
Julian Ospald 2016-05-03 11:19:13 +02:00
parent c84512e3b3
commit 31fe08195f
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
6 changed files with 63 additions and 0 deletions

View File

@ -61,6 +61,7 @@ main = hspec $ before_ fixPermissions $ after_ revertPermissions $ do
, moveFileSpec
, recreateSymlinkSpec
, deleteFileSpec
, deleteDirSpec
]
-- run all stateful tests twice to catch missing cleanups or state skew
@ -625,6 +626,54 @@ deleteFileSpec =
(\e -> ioeGetErrorType e == PermissionDenied)
deleteDirSpec :: Spec
deleteDirSpec =
describe "HSFM.FileSystem.FileOperations.deleteDir" $ do
-- successes --
it "deleteDir, regular file, all fine" $ do
createDir'' "test/deleteDirSpec/testDir"
deleteDir' "test/deleteDirSpec/testDir"
getSymbolicLinkStatus "test/deleteDirSpec/testDir"
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "deleteDir, directory with null permissions, all fine" $ do
createDir'' "test/deleteDirSpec/noPerms/testDir"
noPerms "test/deleteDirSpec/noPerms/testDir"
deleteDir' "test/deleteDirSpec/noPerms/testDir"
-- posix failures --
it "deleteDir, wrong file type (symlink to directory)" $
deleteDir' "test/deleteDirSpec/dirSym"
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "deleteDir, wrong file type (regular file)" $
deleteDir' "test/deleteDirSpec/file"
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "deleteDir, file does not exist" $
deleteDir' "test/deleteDirSpec/doesNotExist"
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "deleteDir, directory not empty" $
deleteDir' "test/deleteDirSpec/dir"
`shouldThrow`
(\e -> ioeGetErrorType e == UnsatisfiedConstraints)
it "deleteDir, can't write to parent directory" $ do
createDir'' "test/deleteDirSpec/noPerms/foo"
noPerms "test/deleteDirSpec/noPerms"
(deleteDir' "test/deleteDirSpec/noPerms/foo"
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied))
>> normalDirPerms "test/deleteDirSpec/noPerms"
>> deleteDir' "test/deleteDirSpec/noPerms/foo"
-----------------
@ -672,6 +721,13 @@ createDir' dest = do
whenM (doesDirectoryExist outputDir) (deleteDir outputDir)
createDir'' :: ByteString -> IO ()
createDir'' dest = do
pwd <- fromJust <$> getEnv "PWD" >>= P.parseAbs
outputDir <- (pwd P.</>) <$> P.parseRel dest
createDir outputDir
createRegularFile' :: ByteString -> IO ()
createRegularFile' dest = do
pwd <- fromJust <$> getEnv "PWD" >>= P.parseAbs
@ -770,3 +826,9 @@ deleteFile' p = do
file <- (pwd P.</>) <$> P.parseRel p
deleteFile file
deleteDir' :: ByteString -> IO ()
deleteDir' p = do
pwd <- fromJust <$> getEnv "PWD" >>= P.parseAbs
file <- (pwd P.</>) <$> P.parseRel p
deleteDir file

0
test/deleteDirSpec/.keep Normal file
View File

View File

1
test/deleteDirSpec/dirSym Symbolic link
View File

@ -0,0 +1 @@
dir

0
test/deleteDirSpec/file Normal file
View File

View File