more detailed tests
This commit is contained in:
parent
15bd70f10a
commit
6c1afb6919
@ -65,7 +65,7 @@ consumeZip handleEntry = Zip.unZipStream `fuseBoth` consumeZip'
|
|||||||
zipEntryName' <- fmap Text.unpack . either throw return . Text.decodeUtf8' $ Zip.zipEntryName e
|
zipEntryName' <- fmap Text.unpack . either throw return . Text.decodeUtf8' $ Zip.zipEntryName e
|
||||||
contentChunks <- accContents
|
contentChunks <- accContents
|
||||||
let
|
let
|
||||||
zipEntryName = normalise $ dropTrailingPathSeparator zipEntryName'
|
zipEntryName = normalise . makeValid $ dropTrailingPathSeparator zipEntryName'
|
||||||
zipEntryTime = localTimeToUTC utc $ Zip.zipEntryTime e
|
zipEntryTime = localTimeToUTC utc $ Zip.zipEntryTime e
|
||||||
zipEntryContents
|
zipEntryContents
|
||||||
| hasTrailingPathSeparator zipEntryName' = Nothing
|
| hasTrailingPathSeparator zipEntryName' = Nothing
|
||||||
@ -101,6 +101,6 @@ produceZip info = Conduit.map toZipData =$= void (Zip.zipStream zipOptions)
|
|||||||
toZipEntry :: Bool -- ^ Is directory?
|
toZipEntry :: Bool -- ^ Is directory?
|
||||||
-> ZipEntry -> Zip.ZipEntry
|
-> ZipEntry -> Zip.ZipEntry
|
||||||
toZipEntry isDir ZipEntry{..} = Zip.ZipEntry
|
toZipEntry isDir ZipEntry{..} = Zip.ZipEntry
|
||||||
{ zipEntryName = Text.encodeUtf8 . Text.pack . bool dropTrailingPathSeparator addTrailingPathSeparator isDir . normalise $ zipEntryName
|
{ zipEntryName = Text.encodeUtf8 . Text.pack . normalise . makeValid . bool dropTrailingPathSeparator addTrailingPathSeparator isDir $ zipEntryName
|
||||||
, zipEntryTime = utcToLocalTime utc zipEntryTime
|
, zipEntryTime = utcToLocalTime utc zipEntryTime
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import Data.Conduit.Binary (sourceLbs, sinkLbs)
|
|||||||
|
|
||||||
instance Arbitrary ZipEntry where
|
instance Arbitrary ZipEntry where
|
||||||
arbitrary = do
|
arbitrary = do
|
||||||
zipEntryName <- normalise . dropTrailingPathSeparator . joinPath <$> arbitrary
|
zipEntryName <- joinPath <$> arbitrary
|
||||||
zipEntryTime <- arbitrary
|
zipEntryTime <- arbitrary
|
||||||
zipEntryContents <- arbitrary
|
zipEntryContents <- arbitrary
|
||||||
return ZipEntry{..}
|
return ZipEntry{..}
|
||||||
@ -27,4 +27,7 @@ spec = describe "Zip file handling" $ do
|
|||||||
\zipFiles -> do
|
\zipFiles -> do
|
||||||
bs <- runConduit $ Conduit.sourceList zipFiles =$= produceZip def =$= sinkLbs
|
bs <- runConduit $ Conduit.sourceList zipFiles =$= produceZip def =$= sinkLbs
|
||||||
(_, zipFiles') <- runConduit $ sourceLbs bs =$= consumeZip return
|
(_, zipFiles') <- runConduit $ sourceLbs bs =$= consumeZip return
|
||||||
zipFiles' `shouldBe` zipFiles
|
forM_ (zip zipFiles zipFiles') $ \(file, file') -> do
|
||||||
|
(shouldBe `on` normalise . makeValid . dropTrailingPathSeparator) (zipEntryName file') (zipEntryName file)
|
||||||
|
-- (zipEntryTime file') `shouldBe` (zipEntryTime file)
|
||||||
|
(zipEntryContents file') `shouldBe` (zipEntryContents file)
|
||||||
|
|||||||
Reference in New Issue
Block a user