summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-06 21:49:19 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-06 21:49:19 +0400
commit541eb8c462cd1f6f3a1aaaaddf15674b2f953795 (patch)
tree685952bf47687a149bf3e7b235ea634c51d69aed /tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs
parent25c46cddb6498155e2b8b07d85f900c4a950267e (diff)
Separate HTTP/UDP tracker response validation
Diffstat (limited to 'tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs')
-rw-r--r--tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs29
1 files changed, 20 insertions, 9 deletions
diff --git a/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs b/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs
index 81c4fae0..3e24c0f4 100644
--- a/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs
+++ b/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs
@@ -1,23 +1,32 @@
1{-# LANGUAGE RecordWildCards #-}
1module Network.BitTorrent.Tracker.RPC.HTTPSpec (spec, trackerURIs) where 2module Network.BitTorrent.Tracker.RPC.HTTPSpec (spec, trackerURIs) where
2 3
4import Control.Applicative
3import Control.Monad 5import Control.Monad
4import Control.Monad.Trans.Resource
5import Data.Default 6import Data.Default
6import Data.List as L 7import Data.List as L
7import Data.Maybe 8import Data.Maybe
8import Network.URI 9import Network.URI
9import Test.Hspec 10import Test.Hspec
10 11
11import Network.BitTorrent.Tracker.MessageSpec hiding (spec) 12import Data.Torrent.Progress
13import Network.BitTorrent.Tracker.Message as Message
12import Network.BitTorrent.Tracker.RPC.HTTP 14import Network.BitTorrent.Tracker.RPC.HTTP
13 15
14 16-- TODO add a good working tracker!
15trackerURIs :: [URI] 17trackerURIs :: [URI]
16trackerURIs = 18trackerURIs = fmap (fromJust . parseURI)
17 [ fromJust $ parseURI "http://announce.opensharing.org:2710/announce" 19 [ "http://tracker.openbittorrent.com:80/announce"
18 , fromJust $ parseURI "http://exodus.desync.com/announce" 20 , "http://tracker.publicbt.com:80/announce"
19 ] 21 ]
20 22
23validateInfo :: AnnounceQuery -> AnnounceInfo -> Expectation
24validateInfo _ Message.Failure {..} = error "validateInfo: failure"
25validateInfo AnnounceQuery {..} AnnounceInfo {..} = do
26 case respComplete <|> respIncomplete of
27 Nothing -> return ()
28 Just n -> n `shouldBe` L.length (getPeerList respPeers)
29
21spec :: Spec 30spec :: Spec
22spec = do 31spec = do
23 forM_ trackerURIs $ \ uri -> 32 forM_ trackerURIs $ \ uri ->
@@ -25,12 +34,14 @@ spec = do
25 describe "announce" $ do 34 describe "announce" $ do
26 it "have valid response" $ do 35 it "have valid response" $ do
27 withManager def $ \ mgr -> do 36 withManager def $ \ mgr -> do
28 q <- arbitrarySample 37-- q <- arbitrarySample
29 info <- runResourceT $ announce mgr uri q 38 let q = AnnounceQuery def "-HS0003-203534.37420" 6000
39 (Progress 0 0 0) Nothing Nothing (Just Started)
40 info <- announce mgr uri q
30 validateInfo q info 41 validateInfo q info
31 42
32 describe "scrape" $ do 43 describe "scrape" $ do
33 it "have valid response" $ do 44 it "have valid response" $ do
34 withManager def $ \ mgr -> do 45 withManager def $ \ mgr -> do
35 xs <- runResourceT $ scrape mgr uri [def] 46 xs <- scrape mgr uri [def]
36 L.length xs `shouldSatisfy` (>= 1) 47 L.length xs `shouldSatisfy` (>= 1)