]> git.rkrishnan.org Git - functorrent.git/blob - test/MetainfoTests.hs
metainfotest: add a piecelength test
[functorrent.git] / test / MetainfoTests.hs
1 -- | Tests for Metainfo module
2
3 module MetainfoTests where
4
5 import Prelude hiding (readFile)
6
7 import FuncTorrent.Metainfo
8 import Test.Hspec
9 import Data.ByteString (readFile)
10
11 tests :: IO ()
12 tests = hspec $ do
13   describe "read and interpret a torrent file 1" $ do
14     it "valid torrent file" $ do
15       fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent"
16       (torrentToMetainfo fc) `shouldNotBe` (Left "parse error")
17     it "valid announce list" $ do
18       fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent"
19       case torrentToMetainfo fc of
20         Left _ -> pending
21         Right metainfo -> do
22           announceList metainfo `shouldSatisfy` (not . null)
23     it "valid piece length" $ do
24       fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent"
25       case torrentToMetainfo fc of
26         Left _ -> pending
27         Right metainfo -> do
28           let (Just info') = info metainfo
29           pieceLength info' `shouldBe` (524288 :: Integer)
30