diff options
Diffstat (limited to 'tests/Network/BitTorrent/Tracker/RPCSpec.hs')
-rw-r--r-- | tests/Network/BitTorrent/Tracker/RPCSpec.hs | 47 |
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 #-} | ||
1 | module Network.BitTorrent.Tracker.RPCSpec (spec) where | 2 | module Network.BitTorrent.Tracker.RPCSpec (spec) where |
2 | import Control.Applicative | 3 | import Control.Applicative |
3 | import Control.Monad | 4 | import Control.Monad |
4 | import Data.Default | 5 | import Data.Default |
5 | import Data.List as L | 6 | import Data.List as L |
6 | import Network.URI | ||
7 | import Test.Hspec | 7 | import Test.Hspec |
8 | import Test.QuickCheck | 8 | import Test.QuickCheck |
9 | 9 | ||
10 | import Network.BitTorrent.Tracker.MessageSpec hiding (spec) | ||
11 | import Network.BitTorrent.Tracker.RPC.HTTPSpec as HTTP hiding (spec) | ||
12 | import Network.BitTorrent.Tracker.RPC.UDPSpec as UDP hiding (spec) | ||
13 | import Network.BitTorrent.Tracker.RPC as RPC | 10 | import Network.BitTorrent.Tracker.RPC as RPC |
14 | 11 | ||
15 | uris :: [URI] | 12 | import Network.BitTorrent.Tracker.TestData |
16 | uris = UDP.trackerURIs ++ HTTP.trackerURIs | 13 | import Network.BitTorrent.Tracker.MessageSpec hiding (spec) |
14 | import qualified Network.BitTorrent.Tracker.RPC.UDPSpec as UDP (rpcOpts) | ||
15 | |||
17 | 16 | ||
18 | instance Arbitrary SAnnounceQuery where | 17 | instance Arbitrary SAnnounceQuery where |
19 | arbitrary = SAnnounceQuery <$> arbitrary <*> arbitrary | 18 | arbitrary = SAnnounceQuery <$> arbitrary <*> arbitrary |
20 | <*> arbitrary <*> arbitrary | 19 | <*> arbitrary <*> arbitrary |
21 | 20 | ||
21 | rpcOpts :: Options | ||
22 | rpcOpts = def | ||
23 | { optUdpRPC = UDP.rpcOpts | ||
24 | } | ||
25 | |||
22 | spec :: Spec | 26 | spec :: Spec |
23 | spec = do | 27 | spec = 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 | ||