diff options
Diffstat (limited to 'tests/Network/BitTorrent/Tracker/SessionSpec.hs')
-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) |