diff options
Diffstat (limited to 'tests/Network/BitTorrent/DHT/MessageSpec.hs')
-rw-r--r-- | tests/Network/BitTorrent/DHT/MessageSpec.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/Network/BitTorrent/DHT/MessageSpec.hs b/tests/Network/BitTorrent/DHT/MessageSpec.hs index af694470..0d84c919 100644 --- a/tests/Network/BitTorrent/DHT/MessageSpec.hs +++ b/tests/Network/BitTorrent/DHT/MessageSpec.hs | |||
@@ -1,6 +1,7 @@ | |||
1 | {-# LANGUAGE RecordWildCards #-} | 1 | {-# LANGUAGE RecordWildCards #-} |
2 | module Network.BitTorrent.DHT.MessageSpec (spec) where | 2 | module Network.BitTorrent.DHT.MessageSpec (spec) where |
3 | import Control.Monad.Reader | 3 | import Control.Monad.Reader |
4 | import Control.Monad.Logger | ||
4 | import Control.Concurrent | 5 | import Control.Concurrent |
5 | import Data.BEncode as BE | 6 | import Data.BEncode as BE |
6 | import Data.ByteString.Lazy as BL | 7 | import Data.ByteString.Lazy as BL |
@@ -8,7 +9,8 @@ import Data.Default | |||
8 | import Data.List as L | 9 | import Data.List as L |
9 | import Network.BitTorrent.Core | 10 | import Network.BitTorrent.Core |
10 | import Network.BitTorrent.DHT.Message | 11 | import Network.BitTorrent.DHT.Message |
11 | import Network.KRPC | 12 | import qualified Network.KRPC as KRPC (def) |
13 | import Network.KRPC hiding (def) | ||
12 | import Network.Socket (PortNumber) | 14 | import Network.Socket (PortNumber) |
13 | import Test.Hspec | 15 | import Test.Hspec |
14 | import Test.QuickCheck | 16 | import Test.QuickCheck |
@@ -18,6 +20,10 @@ import Network.BitTorrent.CoreSpec () | |||
18 | import Network.BitTorrent.DHT.TokenSpec () | 20 | import Network.BitTorrent.DHT.TokenSpec () |
19 | import Data.Torrent.InfoHashSpec () | 21 | import Data.Torrent.InfoHashSpec () |
20 | 22 | ||
23 | |||
24 | instance MonadLogger IO where | ||
25 | monadLoggerLog _ _ _ _ = return () | ||
26 | |||
21 | remoteAddr :: SockAddr | 27 | remoteAddr :: SockAddr |
22 | remoteAddr = SockAddrInet 6881 (256 * 256 * 256 + 127) | 28 | remoteAddr = SockAddrInet 6881 (256 * 256 * 256 + 127) |
23 | 29 | ||
@@ -29,12 +35,12 @@ thisPort = 60001 | |||
29 | 35 | ||
30 | rpc :: ReaderT (Manager IO) IO a -> IO a | 36 | rpc :: ReaderT (Manager IO) IO a -> IO a |
31 | rpc action = do | 37 | rpc action = do |
32 | withManager thisAddr [] $ runReaderT $ do | 38 | withManager KRPC.def thisAddr [] $ runReaderT $ do |
33 | listen | 39 | listen |
34 | action | 40 | action |
35 | 41 | ||
36 | isProtocolError :: KError -> Bool | 42 | isQueryError :: QueryFailure -> Bool |
37 | isProtocolError KError {..} = errorCode == ProtocolError | 43 | isQueryError _ = True |
38 | 44 | ||
39 | prop_bencode :: Eq a => Show a => BEncode a => a -> Expectation | 45 | prop_bencode :: Eq a => Show a => BEncode a => a -> Expectation |
40 | prop_bencode x = BE.decode (BL.toStrict (BE.encode x)) `shouldBe` Right x | 46 | prop_bencode x = BE.decode (BL.toStrict (BE.encode x)) `shouldBe` Right x |
@@ -196,5 +202,5 @@ spec = do | |||
196 | let _ = peers :: Either [NodeInfo IPv4] [PeerAddr IPv4] | 202 | let _ = peers :: Either [NodeInfo IPv4] [PeerAddr IPv4] |
197 | let invalidToken = "" | 203 | let invalidToken = "" |
198 | query remoteAddr (Query nid (Announce False def thisPort invalidToken))) | 204 | query remoteAddr (Query nid (Announce False def thisPort invalidToken))) |
199 | `shouldThrow` isProtocolError | 205 | `shouldThrow` isQueryError |
200 | return () | 206 | return () |