Skip to content

Commit

Permalink
Write a property test for large file sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Dec 10, 2023
1 parent 7adb980 commit 0926e16
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion test/Codec/Archive/Tar/Pack/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import qualified Data.ByteString.Lazy as BL
import Data.FileEmbed
import qualified Codec.Archive.Tar as Tar
import qualified Codec.Archive.Tar.Pack as Pack
import Codec.Archive.Tar.Types (GenEntries(..), Entries)
import Codec.Archive.Tar.Types (GenEntries(..), Entries, simpleEntry, toTarPath)
import qualified Codec.Archive.Tar.Unpack as Unpack
import qualified Codec.Archive.Tar.Write as Write
import Control.Exception
import Data.List.NonEmpty (NonEmpty(..))
import System.Directory
Expand Down
13 changes: 13 additions & 0 deletions test/Codec/Archive/Tar/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ module Codec.Archive.Tar.Tests (
prop_write_read_ustar,
prop_write_read_gnu,
prop_write_read_v7,
prop_large_filesize,
) where

import Codec.Archive.Tar
import Codec.Archive.Tar.Types
import Codec.Archive.Tar.Types.Tests
import qualified Data.ByteString.Lazy as BL
import Prelude hiding (read)
import Test.Tasty.QuickCheck

Expand All @@ -40,3 +42,14 @@ prop_write_read_v7 entries =
foldr Next Done entries' === read (write entries')
where
entries' = map limitToV7FormatCompat $ filter ((== V7Format) . entryFormat) entries

prop_large_filesize :: Word -> Property
prop_large_filesize n = sz === sz'
where
sz = fromIntegral $ n * 1024 * 1024 * 128
Right fn = toTarPath False "Large.file"
entry = simpleEntry fn (NormalFile (BL.replicate sz 42) sz)
-- Trim the tail so it does not blow up RAM
tar = BL.take 2048 $ write [entry]
Next entry' _ = read tar
NormalFile _ sz' = entryContent entry'
4 changes: 2 additions & 2 deletions test/Properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ main =
, testGroup "write/read" [
testProperty "ustar format" Tar.prop_write_read_ustar,
testProperty "gnu format" Tar.prop_write_read_gnu,
testProperty "v7 format" Tar.prop_write_read_v7
testProperty "v7 format" Tar.prop_write_read_v7,
testProperty "large filesize" Tar.prop_large_filesize
]

, testGroup "string table" [
Expand Down Expand Up @@ -73,4 +74,3 @@ main =
testProperty "modtime 1970-01-01" Unpack.case_modtime_1970
]
]

0 comments on commit 0926e16

Please sign in to comment.