From 70a172a43d5b34853289bbf57c3e5a168431a954 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Tue, 18 Mar 2014 00:18:00 +0400 Subject: Spec `getStatus` and notify `dependency` --- tests/Network/BitTorrent/Tracker/SessionSpec.hs | 32 ++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'tests/Network/BitTorrent/Tracker') 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 @@ module Network.BitTorrent.Tracker.SessionSpec (spec) where import Data.Default import Data.List as L -import Network.URI import Test.Hspec import Data.Torrent @@ -10,15 +9,36 @@ import Network.BitTorrent.Tracker.List import Network.BitTorrent.Tracker.RPC import Network.BitTorrent.Tracker.Session -import Network.BitTorrent.Tracker.TestData +import Config +testSession :: (Manager -> Session -> IO ()) -> IO () +testSession action = do + t <- getTestTorrent + withManager def def $ \ m -> + withSession (idInfoHash (tInfoDict t)) (trackerList t) $ \ s -> + action m s spec :: Spec spec = do describe "Session" $ do - it "" $ do - withManager def def $ \ m -> do - s <- newSession def undefined + it "start new session in paused state" $ do + testSession $ \ _ s -> do + status <- getStatus s + status `shouldBe` Paused + + describe "Query" $ do + it "change status after notify" $ do + testSession $ \ m s -> do + notify m s Started + status <- getStatus s + status `shouldBe` Running + + notify m s Stopped + stopped <- getStatus s + stopped `shouldBe` Paused + + it "return non-empty list of peers" $ do + testSession $ \ m s -> do notify m s Started peers <- askPeers m s - peers `shouldSatisfy` (not . L.null) \ No newline at end of file + peers `shouldSatisfy` (not . L.null) -- cgit v1.2.3