From 3df259705da435416c0efe274f1f2bf251d90c15 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Wed, 26 Feb 2014 13:25:31 +0400 Subject: Add test data for tracker rpc --- tests/Network/BitTorrent/Tracker/TestData.hs | 71 ++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/Network/BitTorrent/Tracker/TestData.hs (limited to 'tests/Network') diff --git a/tests/Network/BitTorrent/Tracker/TestData.hs b/tests/Network/BitTorrent/Tracker/TestData.hs new file mode 100644 index 00000000..5d9718e5 --- /dev/null +++ b/tests/Network/BitTorrent/Tracker/TestData.hs @@ -0,0 +1,71 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} +module Network.BitTorrent.Tracker.TestData + ( TrackerEntry (..) + , trackers + ) where + +import Data.Maybe +import Data.String +import Network.URI + +import Data.Torrent.InfoHash + + +data TrackerEntry = TrackerEntry + { -- | May be used to show tracker name in test suite report. + trackerName :: String + + -- | Announce uri of the tracker. + , trackerURI :: URI + + -- | Some trackers abadoned, so don't even try to announce. + , tryAnnounce :: Bool + + -- | Some trackers do not support scraping, so we should not even + -- try to scrape them. + , tryScraping :: Bool + + -- | Some trackers allow + , hashList :: Maybe [InfoHash] + } + +instance IsString URI where + fromString str = fromMaybe err $ parseURI str + where + err = error $ "fromString: bad URI " ++ show str + +trackerEntry :: URI -> TrackerEntry +trackerEntry uri = TrackerEntry + { trackerName = maybe "" uriRegName (uriAuthority uri) + , trackerURI = uri + , tryAnnounce = False + , tryScraping = False + , hashList = Nothing + } + +announceOnly :: String -> URI -> TrackerEntry +announceOnly name uri = (trackerEntry uri) + { trackerName = name + , tryAnnounce = True + } + +announceScrape :: String -> URI -> TrackerEntry +announceScrape name uri = (announceOnly name uri) + { tryScraping = True + } + +notWorking :: String -> URI -> TrackerEntry +notWorking name uri = (trackerEntry uri) + { trackerName = name + } + +trackers :: [TrackerEntry] +trackers = + [ announceOnly "LinuxTracker" + "http://linuxtracker.org:2710/00000000000000000000000000000000/announce" + + , announceScrape "OpenBitTorrent" "udp://tracker.openbittorrent.com:80/announce" + , announceScrape "PublicBT" "udp://tracker.publicbt.com:80/announce" + , notWorking "OpenBitTorrent" "http://tracker.openbittorrent.com:80/announce" + , notWorking "PublicBT" "http://tracker.publicbt.com:80/announce" + ] -- cgit v1.2.3