blob: 03379136d23d9cd30632e0f5b8fb62bcaeb13750 (
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
41
|
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 URI
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 uri { uriScheme = "udp://" }) list
let udps = F.sum $ fmap (fromEnum . ("udp://" ==) . uriScheme) xs
udps `shouldBe` pred (L.length uris)
it "traverseTiers" $ do
xs' <- traverseTiers (\ uri -> if uri == L.last uris then return uri
else throwIO (GenericException "")) list
return ()
|