From eb54b4d99fa8683084ced2e8b16ae18b819a35df Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Wed, 26 Feb 2014 15:33:05 +0400 Subject: Use TestData in tracker spec --- tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs | 51 +++++++++++++----------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs') diff --git a/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs b/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs index 3e24c0f4..f9eb62d9 100644 --- a/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs +++ b/tests/Network/BitTorrent/Tracker/RPC/HTTPSpec.hs @@ -1,24 +1,18 @@ {-# LANGUAGE RecordWildCards #-} -module Network.BitTorrent.Tracker.RPC.HTTPSpec (spec, trackerURIs) where +module Network.BitTorrent.Tracker.RPC.HTTPSpec (spec) where import Control.Applicative import Control.Monad import Data.Default import Data.List as L -import Data.Maybe -import Network.URI import Test.Hspec import Data.Torrent.Progress import Network.BitTorrent.Tracker.Message as Message import Network.BitTorrent.Tracker.RPC.HTTP --- TODO add a good working tracker! -trackerURIs :: [URI] -trackerURIs = fmap (fromJust . parseURI) - [ "http://tracker.openbittorrent.com:80/announce" - , "http://tracker.publicbt.com:80/announce" - ] +import Network.BitTorrent.Tracker.TestData + validateInfo :: AnnounceQuery -> AnnounceInfo -> Expectation validateInfo _ Message.Failure {..} = error "validateInfo: failure" @@ -28,20 +22,31 @@ validateInfo AnnounceQuery {..} AnnounceInfo {..} = do Just n -> n `shouldBe` L.length (getPeerList respPeers) spec :: Spec -spec = do - forM_ trackerURIs $ \ uri -> - context (show uri) $ do +spec = parallel $ do + forM_ (L.filter isHttpTracker trackers) $ \ TrackerEntry {..} -> + context trackerName $ do + describe "announce" $ do - it "have valid response" $ do - withManager def $ \ mgr -> do --- q <- arbitrarySample - let q = AnnounceQuery def "-HS0003-203534.37420" 6000 - (Progress 0 0 0) Nothing Nothing (Just Started) - info <- announce mgr uri q - validateInfo q info + if tryAnnounce + then do + it "have valid response" $ do + withManager def $ \ mgr -> do +-- q <- arbitrarySample + let q = AnnounceQuery def "-HS0003-203534.37420" 6000 + (Progress 0 0 0) Nothing Nothing (Just Started) + info <- announce mgr trackerURI q + validateInfo q info + else do + it "should fail with RequestFailed" $ do + pending describe "scrape" $ do - it "have valid response" $ do - withManager def $ \ mgr -> do - xs <- scrape mgr uri [def] - L.length xs `shouldSatisfy` (>= 1) + if tryScraping + then do + it "have valid response" $ do + withManager def $ \ mgr -> do + xs <- scrape mgr trackerURI [def] + L.length xs `shouldSatisfy` (>= 1) + else do + it "should fail with ScrapelessTracker" $ do + pending -- cgit v1.2.3