Tests use env variable to find mongodb host
This commit is contained in:
parent
24f060b9d9
commit
a11d573ff1
3 changed files with 12 additions and 3 deletions
|
@ -5,11 +5,15 @@ import Database.MongoDB.Connection (connect, host)
|
|||
import Database.MongoDB.Query (access, slaveOk)
|
||||
import Data.Text (unpack)
|
||||
import Test.Hspec.Runner
|
||||
import System.Environment (getEnv)
|
||||
import System.IO.Error (catchIOError)
|
||||
import TestImport
|
||||
import qualified Spec
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
p <- connect $ host "localhost"
|
||||
mongodbHost <- getEnv mongodbHostEnvVariable `catchIOError` (\_ -> return "localhost")
|
||||
p <- connect $ host mongodbHost
|
||||
version <- access p slaveOk "admin" serverVersion
|
||||
putStrLn $ "Running tests with mongodb version: " ++ (unpack version)
|
||||
hspecWith defaultConfig Spec.spec
|
||||
|
|
|
@ -6,6 +6,8 @@ import Data.String (IsString(..))
|
|||
import TestImport
|
||||
import Control.Exception
|
||||
import Control.Monad (forM_)
|
||||
import System.Environment (getEnv)
|
||||
import System.IO.Error (catchIOError)
|
||||
import qualified Data.List as L
|
||||
|
||||
import qualified Data.Text as T
|
||||
|
@ -15,7 +17,8 @@ testDBName = "mongodb-haskell-test"
|
|||
|
||||
db :: Action IO a -> IO a
|
||||
db action = do
|
||||
pipe <- connect (host "127.0.0.1")
|
||||
mongodbHost <- getEnv mongodbHostEnvVariable `catchIOError` (\_ -> return "localhost")
|
||||
pipe <- connect (host mongodbHost)
|
||||
result <- access pipe master testDBName action
|
||||
close pipe
|
||||
return result
|
||||
|
|
|
@ -8,7 +8,6 @@ module TestImport (
|
|||
import Test.Hspec as Export hiding (Selector)
|
||||
import Database.MongoDB as Export
|
||||
import Control.Monad.Trans as Export (MonadIO, liftIO)
|
||||
import Data.Maybe (fromJust)
|
||||
import Data.Time (ParseTime, UTCTime)
|
||||
import qualified Data.Time as Time
|
||||
|
||||
|
@ -32,3 +31,6 @@ parseDate = parseTime (iso8601DateFormat Nothing)
|
|||
|
||||
parseDateTime :: String -> UTCTime
|
||||
parseDateTime = parseTime (iso8601DateFormat (Just "%H:%M:%S"))
|
||||
|
||||
mongodbHostEnvVariable :: String
|
||||
mongodbHostEnvVariable = "HASKELL_MONGODB_TEST_HOST"
|
||||
|
|
Loading…
Reference in a new issue