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"