diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-03-18 00:18:00 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-03-18 00:18:00 +0400 |
commit | 70a172a43d5b34853289bbf57c3e5a168431a954 (patch) | |
tree | d47eef9c0c4957088b0454e063cd15d3dc28510f | |
parent | 1c1208c2d66172963faa5422dd61204b1ca1fdf2 (diff) |
Spec `getStatus` and notify `dependency`
-rw-r--r-- | tests/Network/BitTorrent/Tracker/SessionSpec.hs | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/tests/Network/BitTorrent/Tracker/SessionSpec.hs b/tests/Network/BitTorrent/Tracker/SessionSpec.hs index 2abe7bc0..aa87919d 100644 --- a/tests/Network/BitTorrent/Tracker/SessionSpec.hs +++ b/tests/Network/BitTorrent/Tracker/SessionSpec.hs | |||
@@ -1,7 +1,6 @@ | |||
1 | module Network.BitTorrent.Tracker.SessionSpec (spec) where | 1 | module Network.BitTorrent.Tracker.SessionSpec (spec) where |
2 | import Data.Default | 2 | import Data.Default |
3 | import Data.List as L | 3 | import Data.List as L |
4 | import Network.URI | ||
5 | import Test.Hspec | 4 | import Test.Hspec |
6 | 5 | ||
7 | import Data.Torrent | 6 | import Data.Torrent |
@@ -10,15 +9,36 @@ import Network.BitTorrent.Tracker.List | |||
10 | import Network.BitTorrent.Tracker.RPC | 9 | import Network.BitTorrent.Tracker.RPC |
11 | import Network.BitTorrent.Tracker.Session | 10 | import Network.BitTorrent.Tracker.Session |
12 | 11 | ||
13 | import Network.BitTorrent.Tracker.TestData | 12 | import Config |
14 | 13 | ||
14 | testSession :: (Manager -> Session -> IO ()) -> IO () | ||
15 | testSession action = do | ||
16 | t <- getTestTorrent | ||
17 | withManager def def $ \ m -> | ||
18 | withSession (idInfoHash (tInfoDict t)) (trackerList t) $ \ s -> | ||
19 | action m s | ||
15 | 20 | ||
16 | spec :: Spec | 21 | spec :: Spec |
17 | spec = do | 22 | spec = do |
18 | describe "Session" $ do | 23 | describe "Session" $ do |
19 | it "" $ do | 24 | it "start new session in paused state" $ do |
20 | withManager def def $ \ m -> do | 25 | testSession $ \ _ s -> do |
21 | s <- newSession def undefined | 26 | status <- getStatus s |
27 | status `shouldBe` Paused | ||
28 | |||
29 | describe "Query" $ do | ||
30 | it "change status after notify" $ do | ||
31 | testSession $ \ m s -> do | ||
32 | notify m s Started | ||
33 | status <- getStatus s | ||
34 | status `shouldBe` Running | ||
35 | |||
36 | notify m s Stopped | ||
37 | stopped <- getStatus s | ||
38 | stopped `shouldBe` Paused | ||
39 | |||
40 | it "return non-empty list of peers" $ do | ||
41 | testSession $ \ m s -> do | ||
22 | notify m s Started | 42 | notify m s Started |
23 | peers <- askPeers m s | 43 | peers <- askPeers m s |
24 | peers `shouldSatisfy` (not . L.null) \ No newline at end of file | 44 | peers `shouldSatisfy` (not . L.null) |