diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-26 13:25:31 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-26 13:25:31 +0400 |
commit | 3df259705da435416c0efe274f1f2bf251d90c15 (patch) | |
tree | d5f9e151e3d5544a765683d9246f11eb0eca227f | |
parent | d8dba40ba5431182ab6acdcadc619d8c4fa8206a (diff) |
Add test data for tracker rpc
-rw-r--r-- | bittorrent.cabal | 1 | ||||
-rw-r--r-- | tests/Network/BitTorrent/Tracker/TestData.hs | 71 |
2 files changed, 72 insertions, 0 deletions
diff --git a/bittorrent.cabal b/bittorrent.cabal index 92d626eb..f72adb4b 100644 --- a/bittorrent.cabal +++ b/bittorrent.cabal | |||
@@ -202,6 +202,7 @@ test-suite spec | |||
202 | Network.BitTorrent.DHT.RoutingSpec | 202 | Network.BitTorrent.DHT.RoutingSpec |
203 | Network.BitTorrent.DHT.SessionSpec | 203 | Network.BitTorrent.DHT.SessionSpec |
204 | Network.BitTorrent.DHT.TokenSpec | 204 | Network.BitTorrent.DHT.TokenSpec |
205 | Network.BitTorrent.Tracker.TestData | ||
205 | Network.BitTorrent.Tracker.CacheSpec | 206 | Network.BitTorrent.Tracker.CacheSpec |
206 | Network.BitTorrent.Tracker.ListSpec | 207 | Network.BitTorrent.Tracker.ListSpec |
207 | Network.BitTorrent.Tracker.MessageSpec | 208 | Network.BitTorrent.Tracker.MessageSpec |
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 #-} | ||
2 | module Network.BitTorrent.Tracker.TestData | ||
3 | ( TrackerEntry (..) | ||
4 | , trackers | ||
5 | ) where | ||
6 | |||
7 | import Data.Maybe | ||
8 | import Data.String | ||
9 | import Network.URI | ||
10 | |||
11 | import Data.Torrent.InfoHash | ||
12 | |||
13 | |||
14 | data 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 | |||
32 | instance IsString URI where | ||
33 | fromString str = fromMaybe err $ parseURI str | ||
34 | where | ||
35 | err = error $ "fromString: bad URI " ++ show str | ||
36 | |||
37 | trackerEntry :: URI -> TrackerEntry | ||
38 | trackerEntry uri = TrackerEntry | ||
39 | { trackerName = maybe "<unknown>" uriRegName (uriAuthority uri) | ||
40 | , trackerURI = uri | ||
41 | , tryAnnounce = False | ||
42 | , tryScraping = False | ||
43 | , hashList = Nothing | ||
44 | } | ||
45 | |||
46 | announceOnly :: String -> URI -> TrackerEntry | ||
47 | announceOnly name uri = (trackerEntry uri) | ||
48 | { trackerName = name | ||
49 | , tryAnnounce = True | ||
50 | } | ||
51 | |||
52 | announceScrape :: String -> URI -> TrackerEntry | ||
53 | announceScrape name uri = (announceOnly name uri) | ||
54 | { tryScraping = True | ||
55 | } | ||
56 | |||
57 | notWorking :: String -> URI -> TrackerEntry | ||
58 | notWorking name uri = (trackerEntry uri) | ||
59 | { trackerName = name | ||
60 | } | ||
61 | |||
62 | trackers :: [TrackerEntry] | ||
63 | trackers = | ||
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 | ] | ||