summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-30 16:40:34 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-30 16:40:34 +0400
commit58ea9495514fa90cdd0c53a5628372d370a6bd0c (patch)
treef1f78c1ec2263af198aefef60e28d4747d610b81 /tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs
parentbaff7fbe8a491ce743b3fe2eef0e00ee37ee5c98 (diff)
Add tests for http tracker protocol
Diffstat (limited to 'tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs')
-rw-r--r--tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs27
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs b/tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs
index 8e95286a..f8cf052a 100644
--- a/tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs
+++ b/tests/Network/BitTorrent/Tracker/RPC/MessageSpec.hs
@@ -1,7 +1,14 @@
1{-# LANGUAGE RecordWildCards #-}
1{-# OPTIONS -fno-warn-orphans #-} 2{-# OPTIONS -fno-warn-orphans #-}
2module Network.BitTorrent.Tracker.RPC.MessageSpec (spec) where 3module Network.BitTorrent.Tracker.RPC.MessageSpec
4 ( spec
5 , validateInfo
6 , arbitrarySample
7 ) where
3 8
4import Control.Applicative 9import Control.Applicative
10import Data.List as L
11import Data.Maybe
5import Data.Word 12import Data.Word
6import Network 13import Network
7import Test.Hspec 14import Test.Hspec
@@ -11,7 +18,8 @@ import Data.Torrent.InfoHashSpec ()
11import Data.Torrent.ProgressSpec () 18import Data.Torrent.ProgressSpec ()
12import Network.BitTorrent.Core.PeerIdSpec () 19import Network.BitTorrent.Core.PeerIdSpec ()
13 20
14import Network.BitTorrent.Tracker.RPC.Message 21import Network.BitTorrent.Tracker.RPC.Message as Message
22import Network.BitTorrent.Core.PeerAddr
15 23
16 24
17--prop_bencode :: Eq a => BEncode a => a -> Bool 25--prop_bencode :: Eq a => BEncode a => a -> Bool
@@ -31,6 +39,21 @@ instance Arbitrary AnnounceQuery where
31 <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary 39 <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
32 <*> arbitrary <*> arbitrary <*> arbitrary 40 <*> arbitrary <*> arbitrary <*> arbitrary
33 41
42validateInfo :: AnnounceQuery -> AnnounceInfo -> Expectation
43validateInfo _ Message.Failure {..} = error "validateInfo: failure"
44validateInfo AnnounceQuery {..} AnnounceInfo {..} = do
45 respComplete `shouldSatisfy` isJust
46 respIncomplete `shouldSatisfy` isJust
47 respMinInterval `shouldSatisfy` isNothing
48 respWarning `shouldSatisfy` isNothing
49 peerList `shouldSatisfy` L.all (isNothing . peerID)
50 fromJust respComplete + fromJust respIncomplete `shouldBe` L.length peerList
51 where
52 peerList = getPeerList respPeers
53
54arbitrarySample :: Arbitrary a => IO a
55arbitrarySample = L.head <$> sample' arbitrary
56
34spec :: Spec 57spec :: Spec
35spec = do 58spec = do
36 describe "Announce" $ do 59 describe "Announce" $ do