tmp-postgres 1.29.0.1 → 1.30.0.0
raw patch · 5 files changed
+36/−20 lines, 5 files
Files
- CHANGELOG.md +5/−0
- src/Database/Postgres/Temp/Internal.hs +8/−5
- src/Database/Postgres/Temp/Internal/Config.hs +8/−8
- test/Main.hs +14/−6
- tmp-postgres.cabal +1/−1
CHANGELOG.md view
@@ -1,5 +1,10 @@ Changelog for tmp-postgres +1.30.0.0+ #217 verboseConfig is not verbose enough+ #216 cacheAction does not handle ~ properly bug+ #219 verboseConfig creates a database+ 1.29.0.1 #214 Parallel stop is 8 ms faster.
src/Database/Postgres/Temp/Internal.hs view
@@ -250,6 +250,9 @@ , ("log_connections", "on") , ("log_disconnections", "on") , ("client_min_messages", "WARNING")+ , ("log_min_messages", "WARNING")+ , ("log_min_error_statement", "WARNING")+ , ("log_statement", "all") ] {-|@@ -262,7 +265,6 @@ { logger = pure print , postgresConfigFile = verbosePostgresConfig , initDbConfig = pure standardProcessConfig- , createDbConfig = pure standardProcessConfig , postgresConfig = standardProcessConfig } @@ -688,8 +690,9 @@ -- ^ @initial@ 'Config'. -> IO (Either StartError Config) cacheAction cachePath action config = do- let result = config <> fromFilePathConfig cachePath- nonEmpty <- doesFileExist $ cachePath <> "/PG_VERSION"+ fixCachePath <- fixPath cachePath+ let result = config <> fromFilePathConfig fixCachePath+ nonEmpty <- doesFileExist $ fixCachePath <> "/PG_VERSION" case nonEmpty of True -> pure $ pure result@@ -697,10 +700,10 @@ action db -- TODO see if parallel is better throwIfNotSuccess id =<< stopPostgresGracefully db- createDirectoryIfMissing True cachePath+ createDirectoryIfMissing True fixCachePath let snapshotCopyCmd = cpFlags <>- toDataDirectory db <> "/* " <> cachePath+ toDataDirectory db <> "/* " <> fixCachePath system snapshotCopyCmd >>= \case ExitSuccess -> pure $ pure result x -> pure $ Left $ SnapshotCopyFailed snapshotCopyCmd x
src/Database/Postgres/Temp/Internal/Config.hs view
@@ -353,6 +353,13 @@ instance Monoid DirectoryType where mempty = Temporary +fixPath :: FilePath -> IO FilePath+fixPath x = case x of+ '~':rest -> do+ homeDir <- getHomeDirectory+ pure $ homeDir <> "/" <> rest+ xs -> pure xs+ -- | Either create a'CTemporary' directory or do create the directory -- if it does not exist to a 'CPermanent' -- one.@@ -367,14 +374,7 @@ -> IO CompleteDirectoryType setupDirectoryType tempDir pat dirType = case dirType of Temporary -> CTemporary <$> createTempDirectory tempDir pat- Permanent x -> do- dir <- case x of- '~':rest -> do- homeDir <- getHomeDirectory- pure $ homeDir <> "/" <> rest- xs -> pure xs-- pure $ CPermanent dir+ Permanent x -> CPermanent <$> fixPath x -- Remove a temporary directory and ignore errors -- about it not being there.
test/Main.hs view
@@ -10,6 +10,7 @@ import qualified Data.Set as Set import Data.String import qualified Database.PostgreSQL.Simple as PG+import qualified Database.PostgreSQL.Simple.SqlQQ as PG import qualified Database.PostgreSQL.Simple.Options as Client import Database.Postgres.Temp.Internal import Database.Postgres.Temp.Internal.Config@@ -105,6 +106,12 @@ memptyConfigAndAssertion :: ConfigAndAssertion memptyConfigAndAssertion = memptyConfigAndAssertion' "postgres" +countDbs :: PG.Connection -> IO Int+countDbs conn = PG.fromOnly . head <$> PG.query_ conn [PG.sql|+ SELECT COUNT(*)+ FROM pg_catalog.pg_database+ |]+ memptyConfigAndAssertion' :: String -> ConfigAndAssertion memptyConfigAndAssertion' expectedDbName = let@@ -375,8 +382,9 @@ either throwIO pure =<< withConfig (cacheConfig cacheInfo) assertConnection it "postgresql.conf append last wins" $- withConfig' (defaultPostgresConf [("fsync", "on")]) $ \db -> do+ withConfig' (verboseConfig <> defaultPostgresConf [("fsync", "on")]) $ \db -> do toPostgresqlConfigFile db `shouldContain` "fsync=on"+ withConn db $ \conn -> countDbs conn `shouldReturn` 3 -- -- Error Plans. Can't be combined. Just list them out inline since they can't be combined --@@ -389,8 +397,8 @@ let invalidConfig = mempty { connectionTimeout = pure 0 , connectionOptions = mempty- { Client.dbname = pure "doesnotexist"- }+ { Client.dbname = pure "doesnotexist"+ } } withConfig (defaultConfig <> invalidConfig) (const $ pure ())@@ -400,11 +408,11 @@ let invalidConfig = mempty { connectionTimeout = pure maxBound , connectionOptions = mempty- { Client.dbname = pure "doesnotexist"- }+ { Client.dbname = pure "doesnotexist"+ } } - timeout 100000 (withConfig (defaultConfig <> invalidConfig) (const $ pure ()))+ timeout 2000000 (withConfig (defaultConfig <> invalidConfig) (const $ threadDelay 10000000)) `shouldReturn` Nothing {- it "throws StartPostgresFailed if the port is taken" $
tmp-postgres.cabal view
@@ -1,5 +1,5 @@ name: tmp-postgres-version: 1.29.0.1+version: 1.30.0.0 synopsis: Start and stop a temporary postgres description: Start and stop a temporary postgres. See README.md homepage: https://github.com/jfischoff/tmp-postgres#readme