2016-05-03 11:13:07 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2016-05-03 11:27:10 +00:00
|
|
|
module FileSystem.FileOperations.CreateDirSpec where
|
2016-05-03 11:13:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
import Test.Hspec
|
|
|
|
import System.IO.Error
|
|
|
|
(
|
|
|
|
ioeGetErrorType
|
|
|
|
)
|
|
|
|
import GHC.IO.Exception
|
|
|
|
(
|
|
|
|
IOErrorType(..)
|
|
|
|
)
|
|
|
|
import Utils
|
2016-05-08 22:16:26 +00:00
|
|
|
import qualified Data.ByteString as BS
|
|
|
|
import Data.ByteString.UTF8 (toString)
|
|
|
|
|
|
|
|
|
|
|
|
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
|
|
|
|
ba = BS.append
|
|
|
|
|
|
|
|
specDir :: BS.ByteString
|
|
|
|
specDir = "test/FileSystem/FileOperations/createDirSpec/"
|
|
|
|
|
|
|
|
specDir' :: String
|
|
|
|
specDir' = toString specDir
|
2016-05-03 11:13:07 +00:00
|
|
|
|
|
|
|
|
2016-05-08 21:45:51 +00:00
|
|
|
spec :: Spec
|
|
|
|
spec =
|
2016-05-03 11:13:07 +00:00
|
|
|
describe "HSFM.FileSystem.FileOperations.createDir" $ do
|
|
|
|
|
|
|
|
-- successes --
|
|
|
|
it "createDir, all fine" $ do
|
2016-05-08 22:16:26 +00:00
|
|
|
createDir' (specDir `ba` "newDir")
|
|
|
|
removeDirIfExists (specDir `ba` "newDir")
|
2016-05-03 11:13:07 +00:00
|
|
|
|
|
|
|
-- posix failures --
|
|
|
|
it "createDir, can't write to output directory" $
|
2016-05-08 22:16:26 +00:00
|
|
|
createDir' (specDir `ba` "noWritePerms/newDir")
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == PermissionDenied)
|
|
|
|
|
|
|
|
it "createDir, can't open output directory" $
|
2016-05-08 22:16:26 +00:00
|
|
|
createDir' (specDir `ba` "noPerms/newDir")
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == PermissionDenied)
|
|
|
|
|
|
|
|
it "createDir, destination directory already exists" $
|
2016-05-08 22:16:26 +00:00
|
|
|
createDir' (specDir `ba` "alreadyExists")
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == AlreadyExists)
|
|
|
|
|