diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-05 20:06:13 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-05 20:06:13 +0400 |
commit | 3eaa3003d9ece714595dffbf07202ee90336d05f (patch) | |
tree | 4dfa6528139a37dc194da60cb01161ebff9fd5d9 /tests | |
parent | b925e91c5e53a4300e5b0511e8811c5f1af9e803 (diff) |
Add storage streaming
Diffstat (limited to 'tests')
-rw-r--r-- | tests/System/Torrent/StorageSpec.hs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/System/Torrent/StorageSpec.hs b/tests/System/Torrent/StorageSpec.hs index 8267b7a5..d2185961 100644 --- a/tests/System/Torrent/StorageSpec.hs +++ b/tests/System/Torrent/StorageSpec.hs | |||
@@ -1,6 +1,8 @@ | |||
1 | module System.Torrent.StorageSpec (spec) where | 1 | module System.Torrent.StorageSpec (spec) where |
2 | import Control.Exception | 2 | import Control.Exception |
3 | import Data.ByteString.Lazy as BL | 3 | import Data.ByteString.Lazy as BL |
4 | import Data.Conduit as C | ||
5 | import Data.Conduit.List as C | ||
4 | import System.FilePath | 6 | import System.FilePath |
5 | import System.Directory | 7 | import System.Directory |
6 | import System.IO.Unsafe | 8 | import System.IO.Unsafe |
@@ -25,6 +27,12 @@ createLayout :: IO () | |||
25 | createLayout = | 27 | createLayout = |
26 | bracket (open ReadWriteEx 0 layout) close (const (return ())) | 28 | bracket (open ReadWriteEx 0 layout) close (const (return ())) |
27 | 29 | ||
30 | psize :: PieceSize | ||
31 | psize = 16 | ||
32 | |||
33 | pcount :: PieceCount | ||
34 | pcount = 11 | ||
35 | |||
28 | spec :: Spec | 36 | spec :: Spec |
29 | spec = before createLayout $ do | 37 | spec = before createLayout $ do |
30 | describe "writePiece" $ do | 38 | describe "writePiece" $ do |
@@ -56,3 +64,21 @@ spec = before createLayout $ do | |||
56 | withStorage ReadOnly 100 layout $ \ s -> do | 64 | withStorage ReadOnly 100 layout $ \ s -> do |
57 | _ <- readPiece 1 s | 65 | _ <- readPiece 1 s |
58 | readPiece 2 s `shouldThrow` (== InvalidIndex 2) | 66 | readPiece 2 s `shouldThrow` (== InvalidIndex 2) |
67 | |||
68 | describe "sourceStorage" $ do | ||
69 | it "should source all chunks" $ do | ||
70 | withStorage ReadOnly psize layout $ \ s -> do | ||
71 | n <- sourceStorage s $$ C.fold (\ n _ -> succ n) 0 | ||
72 | n `shouldBe` pcount | ||
73 | |||
74 | -- this test should fail if 'sourceStorage' test fail | ||
75 | describe "sinkStorage" $ do | ||
76 | it "should write all chunks" $ do | ||
77 | let byteVal = 0 | ||
78 | let bzeroPiece p = p { pieceData = BL.replicate (BL.length (pieceData p)) byteVal } | ||
79 | let isZeroPiece p = (== byteVal) `BL.all` pieceData p | ||
80 | |||
81 | withStorage ReadWrite psize layout $ \ s -> do | ||
82 | sourceStorage s $= C.map bzeroPiece $$ sinkStorage s | ||
83 | b <- sourceStorage s $$ C.fold (\ b p -> b && isZeroPiece p) True | ||
84 | b `shouldBe` True | ||