diff options
-rw-r--r-- | tests/Config.hs | 16 | ||||
-rw-r--r-- | tests/Network/BitTorrent/Exchange/SessionSpec.hs | 24 |
2 files changed, 27 insertions, 13 deletions
diff --git a/tests/Config.hs b/tests/Config.hs index 3dea6603..b37b727b 100644 --- a/tests/Config.hs +++ b/tests/Config.hs | |||
@@ -11,8 +11,12 @@ module Config | |||
11 | -- * For item specs | 11 | -- * For item specs |
12 | , getEnvOpts | 12 | , getEnvOpts |
13 | , getThisOpts | 13 | , getThisOpts |
14 | , getMyAddr | ||
15 | |||
14 | , getRemoteOpts | 16 | , getRemoteOpts |
15 | , withRemote | 17 | , withRemote |
18 | , withRemoteAddr | ||
19 | |||
16 | , getTestTorrent | 20 | , getTestTorrent |
17 | ) where | 21 | ) where |
18 | 22 | ||
@@ -29,6 +33,7 @@ import System.IO.Unsafe | |||
29 | import Test.Hspec | 33 | import Test.Hspec |
30 | 34 | ||
31 | import Data.Torrent | 35 | import Data.Torrent |
36 | import Network.BitTorrent.Core (IP, PeerAddr (PeerAddr), genPeerId) | ||
32 | 37 | ||
33 | 38 | ||
34 | type ClientName = String | 39 | type ClientName = String |
@@ -138,6 +143,17 @@ withRemote action = do | |||
138 | Nothing -> pendingWith "Remote client isn't running" | 143 | Nothing -> pendingWith "Remote client isn't running" |
139 | Just opts -> action opts | 144 | Just opts -> action opts |
140 | 145 | ||
146 | withRemoteAddr :: (PeerAddr IP -> Expectation) -> Expectation | ||
147 | withRemoteAddr action = do | ||
148 | withRemote $ \ ClientOpts {..} -> | ||
149 | action (PeerAddr Nothing "0.0.0.0" peerPort) | ||
150 | |||
151 | getMyAddr :: IO (PeerAddr (Maybe IP)) | ||
152 | getMyAddr = do | ||
153 | ClientOpts {..} <- getThisOpts | ||
154 | pid <- genPeerId | ||
155 | return $ PeerAddr (Just pid) Nothing peerPort | ||
156 | |||
141 | getTestTorrent :: IO Torrent | 157 | getTestTorrent :: IO Torrent |
142 | getTestTorrent = do | 158 | getTestTorrent = do |
143 | EnvOpts {..} <- getEnvOpts | 159 | EnvOpts {..} <- getEnvOpts |
diff --git a/tests/Network/BitTorrent/Exchange/SessionSpec.hs b/tests/Network/BitTorrent/Exchange/SessionSpec.hs index 9f6f11a1..745649fe 100644 --- a/tests/Network/BitTorrent/Exchange/SessionSpec.hs +++ b/tests/Network/BitTorrent/Exchange/SessionSpec.hs | |||
@@ -1,31 +1,29 @@ | |||
1 | {-# LANGUAGE RecordWildCards #-} | ||
1 | module Network.BitTorrent.Exchange.SessionSpec (spec) where | 2 | module Network.BitTorrent.Exchange.SessionSpec (spec) where |
2 | import Test.Hspec | 3 | import Test.Hspec |
3 | 4 | ||
4 | import Data.Torrent | 5 | import Data.Torrent |
5 | import Network.BitTorrent.Core | 6 | import Network.BitTorrent.Core |
6 | import Network.BitTorrent.Exchange.Session | 7 | import Network.BitTorrent.Exchange.Session as S |
7 | 8 | ||
8 | import Config | 9 | import Config |
9 | 10 | ||
10 | 11 | ||
11 | nullLogger :: LogFun | 12 | nullLogger :: LogFun |
12 | nullLogger _ _ _ _ = return () | 13 | nullLogger _ _ x _ = print x |
13 | |||
14 | getMyAddr :: IO (PeerAddr (Maybe IP)) | ||
15 | getMyAddr = undefined | ||
16 | 14 | ||
17 | spec :: Spec | 15 | spec :: Spec |
18 | spec = do | 16 | spec = do |
19 | describe "metadata exchange" $ do | 17 | describe "metadata exchange" $ do |
20 | it "should fetch info dictionary" $ do | 18 | it "should fetch info dictionary" $ do |
21 | pending | 19 | withRemoteAddr $ \ addr -> do |
22 | {- | 20 | Torrent {..} <- getTestTorrent |
23 | Torrent {..} <- getTestTorrent | 21 | myAddr <- getMyAddr |
24 | ses <- newSession nullLogger addr "" tInfoDict | 22 | ses <- newSession nullLogger myAddr "" tInfoDict |
25 | dict <- waitMetadata ses | 23 | S.insert addr ses |
26 | closeSession ses | 24 | dict <- waitMetadata ses |
27 | dict `shouldBe` tInfoDict | 25 | closeSession ses |
28 | -} | 26 | dict `shouldBe` tInfoDict |
29 | 27 | ||
30 | it "should serve info dictionary" $ do | 28 | it "should serve info dictionary" $ do |
31 | pending | 29 | pending |