summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Tracker/RPCSpec.hs
blob: c3c7f9e20990bc2a9e59d9420741a7a751c5af14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Network.BitTorrent.Tracker.RPCSpec (spec) where
import Control.Applicative
import Control.Monad
import Data.Default
import Data.List as L
import Network.URI
import Test.Hspec
import Test.QuickCheck

import Network.BitTorrent.Tracker.MessageSpec hiding (spec)
import Network.BitTorrent.Tracker.RPC.HTTPSpec as HTTP hiding (spec)
import Network.BitTorrent.Tracker.RPC.UDPSpec as UDP hiding (spec)
import Network.BitTorrent.Tracker.RPC as RPC

uris :: [URI]
uris = UDP.trackerURIs ++ HTTP.trackerURIs

instance Arbitrary SAnnounceQuery where
  arbitrary = SAnnounceQuery <$> arbitrary <*> arbitrary
                             <*> arbitrary <*> arbitrary

spec :: Spec
spec = do
  forM_ uris $ \ uri ->
    context (show uri) $ do
      describe "announce" $ do
        it "have valid response" $ do
          withManager def def $ \ mgr -> do
            q    <- arbitrarySample
            _    <- announce mgr uri q
            return ()

      describe "scrape" $ do
        it "have valid response" $ do
          withManager def def $ \ mgr -> do
            xs <- scrape mgr uri [def]
            L.length xs `shouldSatisfy` (>= 1)