diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-24 16:54:35 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-24 16:54:35 +0400 |
commit | e5a007173eda61ed8a2865aba2638eaf4cc783ef (patch) | |
tree | f47ec4db65f6c59060622758678f31a07bf5b0fe /tests/Config.hs | |
parent | c5114183d5e9776b8bcce9809384dabb702d1b23 (diff) |
Allow to read torrent from spec items
Diffstat (limited to 'tests/Config.hs')
-rw-r--r-- | tests/Config.hs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/tests/Config.hs b/tests/Config.hs index 3dc254a8..3dea6603 100644 --- a/tests/Config.hs +++ b/tests/Config.hs | |||
@@ -13,6 +13,7 @@ module Config | |||
13 | , getThisOpts | 13 | , getThisOpts |
14 | , getRemoteOpts | 14 | , getRemoteOpts |
15 | , withRemote | 15 | , withRemote |
16 | , getTestTorrent | ||
16 | ) where | 17 | ) where |
17 | 18 | ||
18 | import Control.Monad | 19 | import Control.Monad |
@@ -27,6 +28,9 @@ import System.Environment | |||
27 | import System.IO.Unsafe | 28 | import System.IO.Unsafe |
28 | import Test.Hspec | 29 | import Test.Hspec |
29 | 30 | ||
31 | import Data.Torrent | ||
32 | |||
33 | |||
30 | type ClientName = String | 34 | type ClientName = String |
31 | 35 | ||
32 | 36 | ||
@@ -69,16 +73,18 @@ clientOptsParser = ClientOpts | |||
69 | ) | 73 | ) |
70 | 74 | ||
71 | data EnvOpts = EnvOpts | 75 | data EnvOpts = EnvOpts |
72 | { testClient :: Maybe ClientName | 76 | { testClient :: Maybe ClientName |
73 | , remoteOpts :: ClientOpts | 77 | , testTorrents :: [FilePath] |
74 | , thisOpts :: ClientOpts | 78 | , remoteOpts :: ClientOpts |
79 | , thisOpts :: ClientOpts | ||
75 | } | 80 | } |
76 | 81 | ||
77 | instance Default EnvOpts where | 82 | instance Default EnvOpts where |
78 | def = EnvOpts | 83 | def = EnvOpts |
79 | { testClient = Nothing | 84 | { testClient = Just "rtorrent" |
80 | , remoteOpts = defRemoteOpts | 85 | , testTorrents = ["testfile.torrent"] |
81 | , thisOpts = defThisOpts | 86 | , remoteOpts = defRemoteOpts |
87 | , thisOpts = defThisOpts | ||
82 | } | 88 | } |
83 | 89 | ||
84 | findConflicts :: EnvOpts -> [String] | 90 | findConflicts :: EnvOpts -> [String] |
@@ -96,6 +102,7 @@ envOptsParser = EnvOpts | |||
96 | <> metavar "CLIENT" | 102 | <> metavar "CLIENT" |
97 | <> help "torrent client to run" | 103 | <> help "torrent client to run" |
98 | )) | 104 | )) |
105 | <*> pure [] | ||
99 | <*> clientOptsParser | 106 | <*> clientOptsParser |
100 | <*> clientOptsParser | 107 | <*> clientOptsParser |
101 | 108 | ||
@@ -120,7 +127,9 @@ getThisOpts = thisOpts <$> getEnvOpts | |||
120 | 127 | ||
121 | -- | Return 'Nothing' if remote client is not running. | 128 | -- | Return 'Nothing' if remote client is not running. |
122 | getRemoteOpts :: IO (Maybe ClientOpts) | 129 | getRemoteOpts :: IO (Maybe ClientOpts) |
123 | getRemoteOpts = return Nothing | 130 | getRemoteOpts = do |
131 | EnvOpts {..} <- getEnvOpts | ||
132 | return $ const remoteOpts <$> testClient | ||
124 | 133 | ||
125 | withRemote :: (ClientOpts -> Expectation) -> Expectation | 134 | withRemote :: (ClientOpts -> Expectation) -> Expectation |
126 | withRemote action = do | 135 | withRemote action = do |
@@ -129,6 +138,13 @@ withRemote action = do | |||
129 | Nothing -> pendingWith "Remote client isn't running" | 138 | Nothing -> pendingWith "Remote client isn't running" |
130 | Just opts -> action opts | 139 | Just opts -> action opts |
131 | 140 | ||
141 | getTestTorrent :: IO Torrent | ||
142 | getTestTorrent = do | ||
143 | EnvOpts {..} <- getEnvOpts | ||
144 | if L.null testTorrents | ||
145 | then error "getTestTorrent" | ||
146 | else fromFile ("res/" ++ L.head testTorrents) | ||
147 | |||
132 | -- TODO fix EnvOpts parsing | 148 | -- TODO fix EnvOpts parsing |
133 | 149 | ||
134 | -- | Should be used by test suite driver. | 150 | -- | Should be used by test suite driver. |