Skip to content

Commit

Permalink
Added postgres-embedded for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-murzinov committed Oct 15, 2017
1 parent 6361568 commit c1f6c19
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cache:
directories:
- $HOME/.cabsnap
- $HOME/.cabal/packages
- $HOME/.postgres-embedded

before_cache:
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
Expand All @@ -15,16 +16,16 @@ matrix:
include:
- env: CABALVER=1.16 GHCVER=7.6.3
compiler: ": #GHC 7.6.3"
addons: {apt: {packages: [cabal-install-1.16,ghc-7.6.3], sources: [hvr-ghc]}, postgresql: "9.3"}
addons: {apt: {packages: [cabal-install-1.16,ghc-7.6.3], sources: [hvr-ghc]}}
- env: CABALVER=1.18 GHCVER=7.8.4
compiler: ": #GHC 7.8.4"
addons: { apt: {packages: [cabal-install-1.18,ghc-7.8.4], sources: [hvr-ghc]}, postgresql: "9.3"}
addons: { apt: {packages: [cabal-install-1.18,ghc-7.8.4], sources: [hvr-ghc]}}
- env: CABALVER=1.22 GHCVER=7.10.2
compiler: ": #GHC 7.10.2"
addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.2], sources: [hvr-ghc]}, postgresql: "9.3"}
addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.2], sources: [hvr-ghc]}}
- env: CABALVER=1.24 GHCVER=8.0.1
compiler: ": #GHC 8.0.1"
addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.1], sources: [hvr-ghc]}, postgresql: "9.3"}
addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.1], sources: [hvr-ghc]}}

before_install:
- unset CC
Expand Down
1 change: 1 addition & 0 deletions postgresql-simple.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ test-suite test
, text
, time
, vector
, postgres-embedded >= 0.1.7 && <0.2

if !impl(ghc >= 7.6)
build-depends:
Expand Down
11 changes: 9 additions & 2 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE DoAndIfThenElse #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Common
import Database.PostgreSQL.Embedded
import Database.PostgreSQL.Simple.FromField (FromField)
import Database.PostgreSQL.Simple.Types(Query(..),Values(..))
import Database.PostgreSQL.Simple.HStore
Expand Down Expand Up @@ -469,7 +470,7 @@ isSyntaxError SqlError{..} = sqlState == "42601"
-- Note that some tests, such as Notify, use multiple connections, and assume
-- that 'testConnect' connects to the same database every time it is called.
testConnect :: IO Connection
testConnect = connectPostgreSQL ""
testConnect = connectPostgreSQL "host=127.0.0.1 user=postgres dbname=postgres port=46782"

withTestEnv :: (TestEnv -> IO a) -> IO a
withTestEnv cb =
Expand All @@ -482,4 +483,10 @@ withTestEnv cb =
withConn = bracket testConnect close

main :: IO ()
main = withTestEnv $ defaultMain . tests
main = do
let sConfig = StartupConfig True (Version "9.6.5-1")
let dConfig = DBConfig 46782 "postgres"
rc <- startPostgres sConfig dConfig
withTestEnv $ defaultMain . tests
stopPostgres rc
return ()

0 comments on commit c1f6c19

Please sign in to comment.