diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-03-18 18:17:30 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-03-18 18:17:30 +0400 |
commit | ec70fdc102b950a23aad5565a08f10ddb8ef10c7 (patch) | |
tree | ed6750d8df776e4f736bf4cdee6e21c6df5d607e /tests/Network/BitTorrent/Tracker | |
parent | cab485585f87f73274026106235edae7765dd72e (diff) |
Test specs with empty tracker list too
Diffstat (limited to 'tests/Network/BitTorrent/Tracker')
-rw-r--r-- | tests/Network/BitTorrent/Tracker/SessionSpec.hs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/tests/Network/BitTorrent/Tracker/SessionSpec.hs b/tests/Network/BitTorrent/Tracker/SessionSpec.hs index aa87919d..27a9ae1e 100644 --- a/tests/Network/BitTorrent/Tracker/SessionSpec.hs +++ b/tests/Network/BitTorrent/Tracker/SessionSpec.hs | |||
@@ -1,4 +1,5 @@ | |||
1 | module Network.BitTorrent.Tracker.SessionSpec (spec) where | 1 | module Network.BitTorrent.Tracker.SessionSpec (spec) where |
2 | import Control.Monad | ||
2 | import Data.Default | 3 | import Data.Default |
3 | import Data.List as L | 4 | import Data.List as L |
4 | import Test.Hspec | 5 | import Test.Hspec |
@@ -11,24 +12,28 @@ import Network.BitTorrent.Tracker.Session | |||
11 | 12 | ||
12 | import Config | 13 | import Config |
13 | 14 | ||
14 | testSession :: (Manager -> Session -> IO ()) -> IO () | 15 | testSession :: Bool -> (Manager -> Session -> IO ()) -> IO () |
15 | testSession action = do | 16 | testSession runEmpty action = do |
16 | t <- getTestTorrent | 17 | t <- getTestTorrent |
17 | withManager def def $ \ m -> | 18 | withManager def def $ \ m -> do |
18 | withSession (idInfoHash (tInfoDict t)) (trackerList t) $ \ s -> | 19 | withSession (idInfoHash (tInfoDict t)) (trackerList t) $ \ s -> |
19 | action m s | 20 | action m s |
20 | 21 | ||
22 | when runEmpty $ do | ||
23 | withSession (idInfoHash (tInfoDict t)) def $ \ s -> | ||
24 | action m s | ||
25 | |||
21 | spec :: Spec | 26 | spec :: Spec |
22 | spec = do | 27 | spec = do |
23 | describe "Session" $ do | 28 | describe "Session" $ do |
24 | it "start new session in paused state" $ do | 29 | it "start new session in paused state" $ do |
25 | testSession $ \ _ s -> do | 30 | testSession True $ \ _ s -> do |
26 | status <- getStatus s | 31 | status <- getStatus s |
27 | status `shouldBe` Paused | 32 | status `shouldBe` Paused |
28 | 33 | ||
29 | describe "Query" $ do | 34 | describe "Query" $ do |
30 | it "change status after notify" $ do | 35 | it "change status after notify" $ do |
31 | testSession $ \ m s -> do | 36 | testSession True $ \ m s -> do |
32 | notify m s Started | 37 | notify m s Started |
33 | status <- getStatus s | 38 | status <- getStatus s |
34 | status `shouldBe` Running | 39 | status `shouldBe` Running |
@@ -38,7 +43,7 @@ spec = do | |||
38 | stopped `shouldBe` Paused | 43 | stopped `shouldBe` Paused |
39 | 44 | ||
40 | it "return non-empty list of peers" $ do | 45 | it "return non-empty list of peers" $ do |
41 | testSession $ \ m s -> do | 46 | testSession False $ \ m s -> do |
42 | notify m s Started | 47 | notify m s Started |
43 | peers <- askPeers m s | 48 | peers <- askPeers m s |
44 | peers `shouldSatisfy` (not . L.null) | 49 | peers `shouldSatisfy` (not . L.null) |