diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-06 21:43:56 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-06 21:43:56 +0400 |
commit | 25c46cddb6498155e2b8b07d85f900c4a950267e (patch) | |
tree | fcbf9c32ca74eae000883b127c49a46fb25c629f /tests/Network/BitTorrent/Tracker | |
parent | b0d2f2883c9d134b04944d6ec4a4ac15fa516cab (diff) |
Add BEP12: Multitracker Protocol Extension
Diffstat (limited to 'tests/Network/BitTorrent/Tracker')
-rw-r--r-- | tests/Network/BitTorrent/Tracker/ListSpec.hs | 44 |
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 @@ | |||
1 | module Network.BitTorrent.Tracker.ListSpec (spec) where | ||
2 | import Control.Exception | ||
3 | import Data.Default | ||
4 | import Data.Foldable as F | ||
5 | import Data.List as L | ||
6 | import Data.Maybe | ||
7 | import Network.URI | ||
8 | import Test.Hspec | ||
9 | |||
10 | import Data.Torrent | ||
11 | import Network.BitTorrent.Tracker.List | ||
12 | import Network.BitTorrent.Tracker.RPC | ||
13 | |||
14 | |||
15 | uris :: [URI] | ||
16 | uris = fmap (fromJust . parseURI . renderURI) [1..10 :: Int] | ||
17 | where | ||
18 | renderURI n = "http://" ++ show n ++ ".org" | ||
19 | |||
20 | list :: TrackerList URI | ||
21 | list = fromJust $ trackerList def { tAnnounceList = Just [uris] } | ||
22 | |||
23 | spec :: Spec | ||
24 | spec = 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 () | ||