summaryrefslogtreecommitdiff
path: root/tests/System/Torrent
diff options
context:
space:
mode:
Diffstat (limited to 'tests/System/Torrent')
-rw-r--r--tests/System/Torrent/StorageSpec.hs42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/System/Torrent/StorageSpec.hs b/tests/System/Torrent/StorageSpec.hs
new file mode 100644
index 00000000..8d9dfd8f
--- /dev/null
+++ b/tests/System/Torrent/StorageSpec.hs
@@ -0,0 +1,42 @@
1module System.Torrent.StorageSpec (spec) where
2import Control.Exception
3import System.FilePath
4import System.Directory
5import System.IO.Unsafe
6import Test.Hspec
7
8import Data.Torrent.Layout
9import Data.Torrent.Piece
10import System.Torrent.Storage
11
12
13layout :: FileLayout FileSize
14layout =
15 [ (dir </> "_a", 20)
16 , (dir </> "_b", 50)
17 , (dir </> "_c", 100)
18 , (dir </> "_d", 5)
19 ]
20 where
21 dir = unsafePerformIO $ getTemporaryDirectory
22
23createLayout :: IO ()
24createLayout =
25 bracket (open ReadWriteEx 0 layout) close (const (return ()))
26
27spec :: Spec
28spec = before createLayout $ do
29 describe "writePiece" $ do
30 it "should fail gracefully on write operation in RO mode" $ do
31 s <- open ReadOnly 0 layout
32 writePiece (Piece 0 "") s `shouldThrow` (== StorageIsRO)
33 close s
34
35 it "should fail on negative index" $ do
36 withStorage ReadWrite 0 layout $ \ s ->
37 writePiece (Piece (-1) "") s `shouldThrow` (== InvalidIndex (-1))
38
39 describe "readPiece" $ do
40 it "should fail on negative index" $
41 withStorage ReadOnly 0 layout $ \ s ->
42 readPiece (-1) s `shouldThrow` (== InvalidIndex (-1))