diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-06 22:28:21 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-06 22:28:21 +0400 |
commit | 6f3d7093d6e1c2e3c5138da58b850778759435f8 (patch) | |
tree | 7e636aa82fba6924a052e326dca8dd88d2209b81 /tests/System | |
parent | e36b714d8eb0444459ea7051feb7b1c9af4154df (diff) |
Check piece size in the open function
Diffstat (limited to 'tests/System')
-rw-r--r-- | tests/System/Torrent/StorageSpec.hs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/tests/System/Torrent/StorageSpec.hs b/tests/System/Torrent/StorageSpec.hs index 40eaa9c7..30322545 100644 --- a/tests/System/Torrent/StorageSpec.hs +++ b/tests/System/Torrent/StorageSpec.hs | |||
@@ -1,5 +1,4 @@ | |||
1 | module System.Torrent.StorageSpec (spec) where | 1 | module System.Torrent.StorageSpec (spec) where |
2 | import Control.Exception | ||
3 | import Data.ByteString.Lazy as BL | 2 | import Data.ByteString.Lazy as BL |
4 | import Data.Conduit as C | 3 | import Data.Conduit as C |
5 | import Data.Conduit.List as C | 4 | import Data.Conduit.List as C |
@@ -25,8 +24,7 @@ layout = | |||
25 | dir = unsafePerformIO $ getTemporaryDirectory | 24 | dir = unsafePerformIO $ getTemporaryDirectory |
26 | 25 | ||
27 | createLayout :: IO () | 26 | createLayout :: IO () |
28 | createLayout = | 27 | createLayout = withStorage ReadWriteEx 1 layout (const (return ())) |
29 | bracket (open ReadWriteEx 0 layout) close (const (return ())) | ||
30 | 28 | ||
31 | psize :: PieceSize | 29 | psize :: PieceSize |
32 | psize = 16 | 30 | psize = 16 |
@@ -38,16 +36,15 @@ spec :: Spec | |||
38 | spec = before createLayout $ do | 36 | spec = before createLayout $ do |
39 | describe "writePiece" $ do | 37 | describe "writePiece" $ do |
40 | it "should fail gracefully on write operation in RO mode" $ do | 38 | it "should fail gracefully on write operation in RO mode" $ do |
41 | s <- open ReadOnly 0 layout | 39 | withStorage ReadOnly 1 layout $ \ s -> |
42 | writePiece (Piece 0 "") s `shouldThrow` (== StorageIsRO) | 40 | writePiece (Piece 0 "a") s `shouldThrow` (== StorageIsRO) |
43 | close s | ||
44 | 41 | ||
45 | it "should fail if piece size do not match" $ do | 42 | it "should fail if piece size do not match" $ do |
46 | withStorage ReadWrite 1 layout $ \ s -> | 43 | withStorage ReadWrite 1 layout $ \ s -> |
47 | writePiece (Piece 0 "") s `shouldThrow` (== InvalidSize 0) | 44 | writePiece (Piece 0 "") s `shouldThrow` (== InvalidSize 0) |
48 | 45 | ||
49 | it "should fail on negative index" $ do | 46 | it "should fail on negative index" $ do |
50 | withStorage ReadWrite 0 layout $ \ s -> | 47 | withStorage ReadWrite 1 layout $ \ s -> |
51 | writePiece (Piece (-1) "") s `shouldThrow` (== InvalidIndex (-1)) | 48 | writePiece (Piece (-1) "") s `shouldThrow` (== InvalidIndex (-1)) |
52 | 49 | ||
53 | it "should fail on out of upper bound index" $ do | 50 | it "should fail on out of upper bound index" $ do |
@@ -62,7 +59,7 @@ spec = before createLayout $ do | |||
62 | 59 | ||
63 | describe "readPiece" $ do | 60 | describe "readPiece" $ do |
64 | it "should fail on negative index" $ | 61 | it "should fail on negative index" $ |
65 | withStorage ReadOnly 0 layout $ \ s -> | 62 | withStorage ReadOnly 1 layout $ \ s -> |
66 | readPiece (-1) s `shouldThrow` (== InvalidIndex (-1)) | 63 | readPiece (-1) s `shouldThrow` (== InvalidIndex (-1)) |
67 | 64 | ||
68 | it "should fail on out of upper bound index" $ do | 65 | it "should fail on out of upper bound index" $ do |