tmp-postgres 1.0.0.1 → 1.0.0.2
raw patch · 5 files changed
+25/−28 lines, 5 filesdep −postgresql-simple-optsdep ~postgres-options
Dependencies removed: postgresql-simple-opts
Dependency ranges changed: postgres-options
Files
- src/Database/Postgres/Temp/Internal.hs +3/−4
- src/Database/Postgres/Temp/Internal/Core.hs +3/−2
- src/Database/Postgres/Temp/Internal/Partial.hs +3/−5
- test/Database/Postgres/Temp/InternalSpec.hs +14/−13
- tmp-postgres.cabal +2/−4
src/Database/Postgres/Temp/Internal.hs view
@@ -8,8 +8,7 @@ import Database.Postgres.Temp.Internal.Partial import Control.Exception import Control.Monad (void)-import qualified Database.PostgreSQL.Simple.Options as PostgresClient-import qualified Database.PostgreSQL.Simple.PartialOptions as Client+import qualified Database.PostgreSQL.Simple.Options as Client import System.Exit (ExitCode(..)) import Data.ByteString (ByteString) import Control.Monad.Trans.Cont@@ -28,11 +27,11 @@ } -- | Convert a 'DB' to a connection string. Alternatively one can access the--- 'PostgresClient.Options' using+-- 'Client.Options' using -- @postgresProcessClientConfig . dbPostgresProcess@ toConnectionString :: DB -> ByteString toConnectionString- = PostgresClient.toConnectionString+ = Client.toConnectionString . postgresProcessClientConfig . dbPostgresProcess -------------------------------------------------------------------------------
src/Database/Postgres/Temp/Internal/Core.hs view
@@ -19,6 +19,7 @@ import Data.Typeable import System.IO import System.Process+import Data.Monoid -- | Internal events for debugging data Event@@ -132,7 +133,7 @@ ] e <- try $ bracket (PG.connectPostgreSQL theConnectionString) PG.close $ \conn -> PG.execute conn terminationQuery- [PostgresClient.oDbname options]+ [getLast $ PostgresClient.dbname options] case e of Left (_ :: IOError) -> pure () Right _ -> pure ()@@ -176,7 +177,7 @@ -- We assume that 'template1' exist and make connection -- options to test if postgres is ready. let options = postgresPlanClientConfig- { PostgresClient.oDbname = "template1"+ { PostgresClient.dbname = pure "template1" } -- Block until a connection succeeds or postgres crashes
src/Database/Postgres/Temp/Internal/Partial.hs view
@@ -14,7 +14,7 @@ |-} module Database.Postgres.Temp.Internal.Partial where import Database.Postgres.Temp.Internal.Core-import qualified Database.PostgreSQL.Simple.PartialOptions as Client+import qualified Database.PostgreSQL.Simple.Options as Client import GHC.Generics (Generic) import Data.Monoid.Generic import Data.Monoid@@ -246,7 +246,7 @@ data PartialPostgresPlan = PartialPostgresPlan { partialPostgresPlanProcessConfig :: PartialProcessConfig -- ^ Monoid for the @postgres@ ProcessConfig.- , partialPostgresPlanClientConfig :: Client.PartialOptions+ , partialPostgresPlanClientConfig :: Client.Options -- ^ Monoid for the @postgres@ client connection options. } deriving stock (Generic)@@ -257,9 +257,7 @@ -- values are missing. completePostgresPlan :: PartialPostgresPlan -> Either [String] PostgresPlan completePostgresPlan PartialPostgresPlan {..} = validationToEither $ do- postgresPlanClientConfig <-- eitherToValidation $ addErrorContext "partialPostgresPlanClientConfig: " $- Client.completeOptions partialPostgresPlanClientConfig+ let postgresPlanClientConfig = partialPostgresPlanClientConfig postgresPlanProcessConfig <- eitherToValidation $ addErrorContext "partialPostgresPlanProcessConfig: " $ completeProcessConfig partialPostgresPlanProcessConfig
test/Database/Postgres/Temp/InternalSpec.hs view
@@ -12,8 +12,7 @@ import System.Posix.Files import System.IO.Temp import System.Directory-import qualified Database.PostgreSQL.Simple.Options as PostgresClient-import qualified Database.PostgreSQL.Simple.PartialOptions as Client+import qualified Database.PostgreSQL.Simple.Options as Client import Data.String import System.Timeout(timeout) import Control.Monad (void, (<=<))@@ -47,18 +46,20 @@ let Resources {..} = dbResources Plan {..} = resourcesPlan PostgresPlan {..} = planPostgres- PostgresClient.oDbname postgresPlanClientConfig `shouldBe` "test"+ Client.dbname postgresPlanClientConfig `shouldBe` pure "test" let Temporary tmpDataDir = resourcesDataDir tmpDataDir `shouldStartWith` "/tmp/tmp-postgres-data"- let Just port = PostgresClient.oPort postgresPlanClientConfig+ let Just port = getLast $ Client.port postgresPlanClientConfig port `shouldSatisfy` (>32768) let UnixSocket (Temporary unixSocket) = resourcesSocket unixSocket `shouldStartWith` "/tmp/tmp-postgres-socket" postgresPlanClientConfig `shouldBe`- ((PostgresClient.defaultOptions (PostgresClient.oDbname postgresPlanClientConfig))- { PostgresClient.oPort = PostgresClient.oPort postgresPlanClientConfig- , PostgresClient.oHost = PostgresClient.oHost postgresPlanClientConfig- })+ (mempty+ { Client.port = Client.port postgresPlanClientConfig+ , Client.host = Client.host postgresPlanClientConfig+ , Client.dbname = Client.dbname postgresPlanClientConfig+ }+ ) customConfigWork :: (Config -> (DB -> IO ()) -> IO ()) -> Spec customConfigWork action = do@@ -111,9 +112,9 @@ Plan {..} = resourcesPlan actualOptions = postgresPlanClientConfig planPostgres actualPostgresConfig = planConfig- PostgresClient.oUser actualOptions `shouldBe` Just expectedUser- PostgresClient.oDbname actualOptions `shouldBe` expectedDbName- PostgresClient.oPassword actualOptions `shouldBe` Just expectedPassword+ Client.user actualOptions `shouldBe` pure expectedUser+ Client.dbname actualOptions `shouldBe` pure expectedDbName+ Client.password actualOptions `shouldBe` pure expectedPassword lines actualPostgresConfig `shouldContain` defaultPostgresConfig <> [extraConfig] invalidConfigFailsQuickly :: (Config -> IO ()) -> Spec@@ -352,8 +353,8 @@ reloadConfig db - let Just port = PostgresClient.oPort $ postgresProcessClientConfig dbPostgresProcess- Just host = PostgresClient.oHost $ postgresProcessClientConfig dbPostgresProcess+ let Just port = getLast $ Client.port $ postgresProcessClientConfig dbPostgresProcess+ Just host = getLast $ Client.host $ postgresProcessClientConfig dbPostgresProcess backupCommand = "pg_basebackup -D " ++ baseBackupFile ++ " --format=tar -p" ++ show port ++ " -h" ++ host putStrLn backupCommand
tmp-postgres.cabal view
@@ -1,5 +1,5 @@ name: tmp-postgres-version: 1.0.0.1+version: 1.0.0.2 synopsis: Start and stop a temporary postgres description: @tmp-postgres@ provides functions creating a temporary @postgres@ instance.@@ -59,11 +59,10 @@ , network , bytestring , postgresql-simple- , postgres-options+ , postgres-options >= 0.2.0.0 , port-utils , async , generic-monoid- , postgresql-simple-opts >= 0.5.0.1 , either , transformers ghc-options: -Wall@@ -90,7 +89,6 @@ , temporary , either , transformers- , postgresql-simple-opts , postgres-options ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N default-language: Haskell2010