summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs53
1 files changed, 50 insertions, 3 deletions
diff --git a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs
index 4cbaa09d..1a893011 100644
--- a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs
+++ b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs
@@ -1,7 +1,54 @@
1{-# LANGUAGE RecordWildCards #-}
1module Network.BitTorrent.Tracker.RPC.UDPSpec (spec) where 2module Network.BitTorrent.Tracker.RPC.UDPSpec (spec) where
3
4import Control.Applicative
5import Control.Monad
6import Data.Default
7import Data.List as L
8import Data.Maybe
9import Network.URI
2import Test.Hspec 10import Test.Hspec
11import Test.QuickCheck
12
13import Network.BitTorrent.Core.PeerAddr
14import Network.BitTorrent.Tracker.RPC.Message
15import Network.BitTorrent.Tracker.RPC.UDP
16import Network.BitTorrent.Tracker.RPC.MessageSpec ()
17
18
19arbitrarySample :: Arbitrary a => IO a
20arbitrarySample = L.head <$> sample' arbitrary
21
22trackerURIs :: [URI]
23trackerURIs =
24 [ fromJust $ parseURI "udp://tracker.openbittorrent.com:80/announce"
25 , fromJust $ parseURI "udp://tracker.publicbt.com:80/announce"
26 ]
27
28-- relation with query: peer id, numwant
29validateInfo :: AnnounceQuery -> AnnounceInfo -> Expectation
30validateInfo AnnounceQuery {..} AnnounceInfo {..} = do
31 respComplete `shouldSatisfy` isJust
32 respIncomplete `shouldSatisfy` isJust
33 respMinInterval `shouldSatisfy` isNothing
34 respWarning `shouldSatisfy` isNothing
35 peerList `shouldSatisfy` L.all (isNothing . peerID)
36 fromJust respComplete + fromJust respIncomplete `shouldBe` L.length peerList
37 where
38 peerList = getPeerList respPeers
39
3 40
4spec :: Spec 41spec :: Spec
5spec = 42spec = do
6 describe "UDP tracker client RPC" $ do 43 forM_ trackerURIs $ \ uri ->
7 return () \ No newline at end of file 44 context (show uri) $ do
45 describe "announce" $ do
46 it "have valid response" $ do
47 query <- arbitrarySample
48 connect uri >>= announce query >>= validateInfo query
49
50 describe "scrape" $ do
51 it "have valid response" $ do
52 xs <- connect uri >>= scrape [def]
53 return ()
54-- L.length xs `shouldSatisfy` (>= 1)