diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-06 21:49:19 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-06 21:49:19 +0400 |
commit | 541eb8c462cd1f6f3a1aaaaddf15674b2f953795 (patch) | |
tree | 685952bf47687a149bf3e7b235ea634c51d69aed /tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs | |
parent | 25c46cddb6498155e2b8b07d85f900c4a950267e (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.hs | 29 |
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 #-} | ||
1 | module Network.BitTorrent.Tracker.RPC.HTTPSpec (spec, trackerURIs) where | 2 | module Network.BitTorrent.Tracker.RPC.HTTPSpec (spec, trackerURIs) where |
2 | 3 | ||
4 | import Control.Applicative | ||
3 | import Control.Monad | 5 | import Control.Monad |
4 | import Control.Monad.Trans.Resource | ||
5 | import Data.Default | 6 | import Data.Default |
6 | import Data.List as L | 7 | import Data.List as L |
7 | import Data.Maybe | 8 | import Data.Maybe |
8 | import Network.URI | 9 | import Network.URI |
9 | import Test.Hspec | 10 | import Test.Hspec |
10 | 11 | ||
11 | import Network.BitTorrent.Tracker.MessageSpec hiding (spec) | 12 | import Data.Torrent.Progress |
13 | import Network.BitTorrent.Tracker.Message as Message | ||
12 | import Network.BitTorrent.Tracker.RPC.HTTP | 14 | import Network.BitTorrent.Tracker.RPC.HTTP |
13 | 15 | ||
14 | 16 | -- TODO add a good working tracker! | |
15 | trackerURIs :: [URI] | 17 | trackerURIs :: [URI] |
16 | trackerURIs = | 18 | trackerURIs = 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 | ||
23 | validateInfo :: AnnounceQuery -> AnnounceInfo -> Expectation | ||
24 | validateInfo _ Message.Failure {..} = error "validateInfo: failure" | ||
25 | validateInfo AnnounceQuery {..} AnnounceInfo {..} = do | ||
26 | case respComplete <|> respIncomplete of | ||
27 | Nothing -> return () | ||
28 | Just n -> n `shouldBe` L.length (getPeerList respPeers) | ||
29 | |||
21 | spec :: Spec | 30 | spec :: Spec |
22 | spec = do | 31 | spec = 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) |