diff options
Diffstat (limited to 'tests/Network')
-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 () | ||