summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs
blob: 81c4fae0c94baff7cb4c5ac7ab66689efb6b3fd0 (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
module Network.BitTorrent.Tracker.RPC.HTTPSpec (spec, trackerURIs) where

import Control.Monad
import Control.Monad.Trans.Resource
import Data.Default
import Data.List as L
import Data.Maybe
import Network.URI
import Test.Hspec

import Network.BitTorrent.Tracker.MessageSpec hiding (spec)
import Network.BitTorrent.Tracker.RPC.HTTP


trackerURIs :: [URI]
trackerURIs =
  [ fromJust $ parseURI "http://announce.opensharing.org:2710/announce"
  , fromJust $ parseURI "http://exodus.desync.com/announce"
  ]

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

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