summaryrefslogtreecommitdiff
path: root/tests/Network
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-15 19:44:12 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-15 19:44:12 +0400
commitc1e3c9762eb5fea16188a0fb21ad01dd3240ab88 (patch)
treef65cffdb5156c1140dead382d4a29da845e70e53 /tests/Network
parentaee6069785bd552100824e36995e55e72bdbb42e (diff)
Fix bugs in PeerAddr encoding.
Also: * PeerAddr.hs internals and export list have been simplified; * tests added.
Diffstat (limited to 'tests/Network')
-rw-r--r--tests/Network/BitTorrent/Core/PeerIdSpec.hs7
-rw-r--r--tests/Network/BitTorrent/Tracker/MessageSpec.hs36
2 files changed, 41 insertions, 2 deletions
diff --git a/tests/Network/BitTorrent/Core/PeerIdSpec.hs b/tests/Network/BitTorrent/Core/PeerIdSpec.hs
index a4cc30b8..4b0c2398 100644
--- a/tests/Network/BitTorrent/Core/PeerIdSpec.hs
+++ b/tests/Network/BitTorrent/Core/PeerIdSpec.hs
@@ -1,6 +1,7 @@
1{-# OPTIONS -fno-warn-orphans #-} 1{-# OPTIONS -fno-warn-orphans #-}
2module Network.BitTorrent.Core.PeerIdSpec (spec) where 2module Network.BitTorrent.Core.PeerIdSpec (spec) where
3import Control.Applicative 3import Control.Applicative
4import Data.BEncode as BE
4import Data.Text.Encoding as T 5import Data.Text.Encoding as T
5import Test.Hspec 6import Test.Hspec
6import Test.QuickCheck 7import Test.QuickCheck
@@ -17,4 +18,8 @@ instance Arbitrary PeerId where
17 ] 18 ]
18 19
19spec :: Spec 20spec :: Spec
20spec = return () \ No newline at end of file 21spec = do
22 describe "PeerId" $ do
23 it "properly bencoded" $ do
24 BE.decode "20:01234567890123456789"
25 `shouldBe` Right ("01234567890123456789" :: PeerId) \ No newline at end of file
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 ()