summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Tracker
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-06 21:43:56 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-06 21:43:56 +0400
commit25c46cddb6498155e2b8b07d85f900c4a950267e (patch)
treefcbf9c32ca74eae000883b127c49a46fb25c629f /tests/Network/BitTorrent/Tracker
parentb0d2f2883c9d134b04944d6ec4a4ac15fa516cab (diff)
Add BEP12: Multitracker Protocol Extension
Diffstat (limited to 'tests/Network/BitTorrent/Tracker')
-rw-r--r--tests/Network/BitTorrent/Tracker/ListSpec.hs44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/Network/BitTorrent/Tracker/ListSpec.hs b/tests/Network/BitTorrent/Tracker/ListSpec.hs
new file mode 100644
index 00000000..8decd3c9
--- /dev/null
+++ b/tests/Network/BitTorrent/Tracker/ListSpec.hs
@@ -0,0 +1,44 @@
1module Network.BitTorrent.Tracker.ListSpec (spec) where
2import Control.Exception
3import Data.Default
4import Data.Foldable as F
5import Data.List as L
6import Data.Maybe
7import Network.URI
8import Test.Hspec
9
10import Data.Torrent
11import Network.BitTorrent.Tracker.List
12import Network.BitTorrent.Tracker.RPC
13
14
15uris :: [URI]
16uris = fmap (fromJust . parseURI . renderURI) [1..10 :: Int]
17 where
18 renderURI n = "http://" ++ show n ++ ".org"
19
20list :: TrackerList URI
21list = fromJust $ trackerList def { tAnnounceList = Just [uris] }
22
23spec :: Spec
24spec = do
25 describe "TrackerList" $ do
26 it "trackerList is not empty" $ do
27 pending
28
29 it "shuffleTiers (may fail with very small probability)" $ do
30 list' <- shuffleTiers list
31 list' `shouldSatisfy` (/= list)
32
33 it "traverseAll" $ do
34 xs <- traverseAll (\ uri -> if uri == L.last uris
35 then throwIO (GenericException "")
36 else return uri { uriScheme = "udp://" }) list
37 let udps = F.sum $ fmap (fromEnum . ("udp://" ==) . uriScheme) xs
38 udps `shouldBe` pred (L.length uris)
39
40 it "traverseTiers" $ do
41 xs' <- traverseTiers (\ uri -> if uri == L.last uris then return uri
42 else throwIO (GenericException "")) list
43
44 return ()