summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-26 13:25:31 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-26 13:25:31 +0400
commit3df259705da435416c0efe274f1f2bf251d90c15 (patch)
treed5f9e151e3d5544a765683d9246f11eb0eca227f /tests
parentd8dba40ba5431182ab6acdcadc619d8c4fa8206a (diff)
Add test data for tracker rpc
Diffstat (limited to 'tests')
-rw-r--r--tests/Network/BitTorrent/Tracker/TestData.hs71
1 files changed, 71 insertions, 0 deletions
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 @@
1{-# OPTIONS_GHC -fno-warn-orphans #-}
2module Network.BitTorrent.Tracker.TestData
3 ( TrackerEntry (..)
4 , trackers
5 ) where
6
7import Data.Maybe
8import Data.String
9import Network.URI
10
11import Data.Torrent.InfoHash
12
13
14data TrackerEntry = TrackerEntry
15 { -- | May be used to show tracker name in test suite report.
16 trackerName :: String
17
18 -- | Announce uri of the tracker.
19 , trackerURI :: URI
20
21 -- | Some trackers abadoned, so don't even try to announce.
22 , tryAnnounce :: Bool
23
24 -- | Some trackers do not support scraping, so we should not even
25 -- try to scrape them.
26 , tryScraping :: Bool
27
28 -- | Some trackers allow
29 , hashList :: Maybe [InfoHash]
30 }
31
32instance IsString URI where
33 fromString str = fromMaybe err $ parseURI str
34 where
35 err = error $ "fromString: bad URI " ++ show str
36
37trackerEntry :: URI -> TrackerEntry
38trackerEntry uri = TrackerEntry
39 { trackerName = maybe "<unknown>" uriRegName (uriAuthority uri)
40 , trackerURI = uri
41 , tryAnnounce = False
42 , tryScraping = False
43 , hashList = Nothing
44 }
45
46announceOnly :: String -> URI -> TrackerEntry
47announceOnly name uri = (trackerEntry uri)
48 { trackerName = name
49 , tryAnnounce = True
50 }
51
52announceScrape :: String -> URI -> TrackerEntry
53announceScrape name uri = (announceOnly name uri)
54 { tryScraping = True
55 }
56
57notWorking :: String -> URI -> TrackerEntry
58notWorking name uri = (trackerEntry uri)
59 { trackerName = name
60 }
61
62trackers :: [TrackerEntry]
63trackers =
64 [ announceOnly "LinuxTracker"
65 "http://linuxtracker.org:2710/00000000000000000000000000000000/announce"
66
67 , announceScrape "OpenBitTorrent" "udp://tracker.openbittorrent.com:80/announce"
68 , announceScrape "PublicBT" "udp://tracker.publicbt.com:80/announce"
69 , notWorking "OpenBitTorrent" "http://tracker.openbittorrent.com:80/announce"
70 , notWorking "PublicBT" "http://tracker.publicbt.com:80/announce"
71 ]