blob: bba9d0e298e093cda7d85b0d80260a062e4eb4ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
module Network.BitTorrent.Tracker.ListSpec (spec) where
import Control.Exception
import Data.Default
import Data.Foldable as F
import Data.List as L
import Data.Maybe
import Network.URI
import Test.Hspec
import Data.Torrent
import Network.BitTorrent.Tracker.List
import Network.BitTorrent.Tracker.RPC
uris :: [URI]
uris = fmap (fromJust . parseURI . renderURI) [1..10 :: Int]
where
renderURI n = "http://" ++ show n ++ ".org"
list :: TrackerList ()
list = trackerList def { tAnnounceList = Just [uris] }
spec :: Spec
spec = do
describe "TrackerList" $ do
it "shuffleTiers (may fail with very small probability)" $ do
list' <- shuffleTiers list
list' `shouldSatisfy` (/= list)
it "traverseAll" $ do
xs <- traverseAll (\ (uri, _) -> if uri == L.last uris
then throwIO (GenericException "")
else return ()) list
return ()
it "traverseTiers" $ do
xs' <- traverseTiers (\ (uri, _) -> if uri == L.last uris then return ()
else throwIO (GenericException "")) list
return ()
|