summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Tracker/RPCSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Network/BitTorrent/Tracker/RPCSpec.hs')
-rw-r--r--tests/Network/BitTorrent/Tracker/RPCSpec.hs47
1 files changed, 30 insertions, 17 deletions
diff --git a/tests/Network/BitTorrent/Tracker/RPCSpec.hs b/tests/Network/BitTorrent/Tracker/RPCSpec.hs
index c3c7f9e2..3b89714c 100644
--- a/tests/Network/BitTorrent/Tracker/RPCSpec.hs
+++ b/tests/Network/BitTorrent/Tracker/RPCSpec.hs
@@ -1,37 +1,50 @@
1{-# LANGUAGE RecordWildCards #-}
1module Network.BitTorrent.Tracker.RPCSpec (spec) where 2module Network.BitTorrent.Tracker.RPCSpec (spec) where
2import Control.Applicative 3import Control.Applicative
3import Control.Monad 4import Control.Monad
4import Data.Default 5import Data.Default
5import Data.List as L 6import Data.List as L
6import Network.URI
7import Test.Hspec 7import Test.Hspec
8import Test.QuickCheck 8import Test.QuickCheck
9 9
10import Network.BitTorrent.Tracker.MessageSpec hiding (spec)
11import Network.BitTorrent.Tracker.RPC.HTTPSpec as HTTP hiding (spec)
12import Network.BitTorrent.Tracker.RPC.UDPSpec as UDP hiding (spec)
13import Network.BitTorrent.Tracker.RPC as RPC 10import Network.BitTorrent.Tracker.RPC as RPC
14 11
15uris :: [URI] 12import Network.BitTorrent.Tracker.TestData
16uris = UDP.trackerURIs ++ HTTP.trackerURIs 13import Network.BitTorrent.Tracker.MessageSpec hiding (spec)
14import qualified Network.BitTorrent.Tracker.RPC.UDPSpec as UDP (rpcOpts)
15
17 16
18instance Arbitrary SAnnounceQuery where 17instance Arbitrary SAnnounceQuery where
19 arbitrary = SAnnounceQuery <$> arbitrary <*> arbitrary 18 arbitrary = SAnnounceQuery <$> arbitrary <*> arbitrary
20 <*> arbitrary <*> arbitrary 19 <*> arbitrary <*> arbitrary
21 20
21rpcOpts :: Options
22rpcOpts = def
23 { optUdpRPC = UDP.rpcOpts
24 }
25
22spec :: Spec 26spec :: Spec
23spec = do 27spec = do
24 forM_ uris $ \ uri -> 28 forM_ trackers $ \ TrackerEntry {..} ->
25 context (show uri) $ do 29 context trackerName $ do
30
26 describe "announce" $ do 31 describe "announce" $ do
27 it "have valid response" $ do 32 if tryAnnounce then do
28 withManager def def $ \ mgr -> do 33 it "have valid response" $ do
29 q <- arbitrarySample 34 withManager rpcOpts def $ \ mgr -> do
30 _ <- announce mgr uri q 35 q <- arbitrarySample
31 return () 36 _ <- announce mgr trackerURI q
37 return ()
38 else do
39 it "should throw exception" $ do
40 pending
32 41
33 describe "scrape" $ do 42 describe "scrape" $ do
34 it "have valid response" $ do 43 if tryScraping then do
35 withManager def def $ \ mgr -> do 44 it "have valid response" $ do
36 xs <- scrape mgr uri [def] 45 withManager rpcOpts def $ \ mgr -> do
37 L.length xs `shouldSatisfy` (>= 1) 46 xs <- scrape mgr trackerURI [def]
47 L.length xs `shouldSatisfy` (>= 1)
48 else do
49 it "should throw exception" $ do
50 pending