summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Tracker/MessageSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Network/BitTorrent/Tracker/MessageSpec.hs')
-rw-r--r--tests/Network/BitTorrent/Tracker/MessageSpec.hs36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/Network/BitTorrent/Tracker/MessageSpec.hs b/tests/Network/BitTorrent/Tracker/MessageSpec.hs
index ac770905..bf89e717 100644
--- a/tests/Network/BitTorrent/Tracker/MessageSpec.hs
+++ b/tests/Network/BitTorrent/Tracker/MessageSpec.hs
@@ -7,6 +7,8 @@ module Network.BitTorrent.Tracker.MessageSpec
7 ) where 7 ) where
8 8
9import Control.Applicative 9import Control.Applicative
10import Control.Exception
11import Data.BEncode as BE
10import Data.List as L 12import Data.List as L
11import Data.Maybe 13import Data.Maybe
12import Data.Word 14import Data.Word
@@ -56,10 +58,42 @@ arbitrarySample = L.head <$> sample' arbitrary
56 58
57spec :: Spec 59spec :: Spec
58spec = do 60spec = do
59 describe "Announce" $ do 61 describe "AnnounceQuery" $ do
60 it "properly url encoded" $ property $ \ q -> 62 it "properly url encoded" $ property $ \ q ->
61 parseAnnounceQuery (renderAnnounceQuery q) 63 parseAnnounceQuery (renderAnnounceQuery q)
62 `shouldBe` Right q 64 `shouldBe` Right q
63 65
66 describe "AnnounceInfo" $ do
67 it "parses minimal sample" $ do
68 "d8:intervali0e5:peerslee"
69 `shouldBe`
70 AnnounceInfo Nothing Nothing 0 Nothing (PeerList []) Nothing
71
72 it "parses optional fields" $ do
73 "d8:completei1e\
74 \10:incompletei2e\
75 \8:intervali3e\
76 \12:min intervali4e\
77 \5:peersle\
78 \15:warning message3:str\
79 \e"
80 `shouldBe`
81 AnnounceInfo (Just 1) (Just 2) 3 (Just 4) (PeerList []) (Just "str")
82
83 it "parses failed response" $ do
84 "d14:failure reason10:any reasone"
85 `shouldBe`
86 Message.Failure "any reason"
87
88 it "fail if no peer list present" $ do
89 evaluate ("d8:intervali0ee" :: AnnounceInfo)
90 `shouldThrow`
91 errorCall "fromString: unable to decode AnnounceInfo: \
92 \required field `peers' not found"
93
94 it "parses peer list" $ do -- TODO
95 "d8:intervali0e5:peerslee" `shouldBe`
96 AnnounceInfo Nothing Nothing 0 Nothing (PeerList []) Nothing
97
64 describe "Scrape" $ do 98 describe "Scrape" $ do
65 return () 99 return ()