summaryrefslogtreecommitdiff
path: root/tests/Network
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Network')
-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 ()