From a11d573ff1858ec3afe8fdb4a758916ba0264611 Mon Sep 17 00:00:00 2001 From: Victor Denisov Date: Sun, 9 Apr 2017 10:20:10 -0700 Subject: [PATCH] Tests use env variable to find mongodb host --- test/Main.hs | 6 +++++- test/QuerySpec.hs | 5 ++++- test/TestImport.hs | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test/Main.hs b/test/Main.hs index cf3f876..4dd8653 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -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 diff --git a/test/QuerySpec.hs b/test/QuerySpec.hs index 85063fe..bf274ec 100644 --- a/test/QuerySpec.hs +++ b/test/QuerySpec.hs @@ -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 diff --git a/test/TestImport.hs b/test/TestImport.hs index 2294beb..ad15152 100644 --- a/test/TestImport.hs +++ b/test/TestImport.hs @@ -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"