Suppress server logging in test mode
This commit is contained in:
@@ -43,6 +43,7 @@ data AppConfig = AppConfig {
|
|||||||
, configJwtSecret :: Secret
|
, configJwtSecret :: Secret
|
||||||
, configPool :: Int
|
, configPool :: Int
|
||||||
, configMaxRows :: Maybe Integer
|
, configMaxRows :: Maybe Integer
|
||||||
|
, configQuiet :: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
argParser :: Parser AppConfig
|
argParser :: Parser AppConfig
|
||||||
@@ -55,6 +56,7 @@ argParser = AppConfig
|
|||||||
strOption (long "jwt-secret" <> short 'j' <> help "secret used to encrypt and decrypt JWT tokens" <> metavar "SECRET" <> value "secret" <> showDefault))
|
strOption (long "jwt-secret" <> short 'j' <> help "secret used to encrypt and decrypt JWT tokens" <> metavar "SECRET" <> value "secret" <> showDefault))
|
||||||
<*> option auto (long "pool" <> short 'o' <> help "max connections in database pool" <> metavar "COUNT" <> value 10 <> showDefault)
|
<*> option auto (long "pool" <> short 'o' <> help "max connections in database pool" <> metavar "COUNT" <> value 10 <> showDefault)
|
||||||
<*> (readMay <$> strOption (long "max-rows" <> short 'm' <> help "max rows in response" <> metavar "COUNT" <> value "infinity" <> showDefault))
|
<*> (readMay <$> strOption (long "max-rows" <> short 'm' <> help "max rows in response" <> metavar "COUNT" <> value "infinity" <> showDefault))
|
||||||
|
<*> pure False
|
||||||
|
|
||||||
defaultCorsPolicy :: CorsResourcePolicy
|
defaultCorsPolicy :: CorsResourcePolicy
|
||||||
defaultCorsPolicy = CorsResourcePolicy Nothing
|
defaultCorsPolicy = CorsResourcePolicy Nothing
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ main = do
|
|||||||
|
|
||||||
postgrest :: AppConfig -> DbStructure -> P.Pool -> Application
|
postgrest :: AppConfig -> DbStructure -> P.Pool -> Application
|
||||||
postgrest conf dbStructure pool =
|
postgrest conf dbStructure pool =
|
||||||
let middle = logStdout . defaultMiddle in
|
let middle = (if configQuiet conf then id else logStdout) . defaultMiddle in
|
||||||
|
|
||||||
middle $ \ req respond -> do
|
middle $ \ req respond -> do
|
||||||
time <- getPOSIXTime
|
time <- getPOSIXTime
|
||||||
|
|||||||
+2
-2
@@ -23,11 +23,11 @@ main :: IO ()
|
|||||||
main = do
|
main = do
|
||||||
setupDb
|
setupDb
|
||||||
|
|
||||||
pool <- P.acquire (10, 10, cs dbString)
|
pool <- P.acquire (10, 10, cs testDbConn)
|
||||||
|
|
||||||
result <- P.use pool $ getDbStructure "test"
|
result <- P.use pool $ getDbStructure "test"
|
||||||
let dbStructure = either (error.show) id result
|
let dbStructure = either (error.show) id result
|
||||||
withApp = return $ postgrest cfgDefault dbStructure pool
|
withApp = return $ postgrest testCfg dbStructure pool
|
||||||
|
|
||||||
hspec . sequence_ . map (before withApp) $ specs
|
hspec . sequence_ . map (before withApp) $ specs
|
||||||
|
|
||||||
|
|||||||
+5
-10
@@ -14,17 +14,12 @@ import Web.JWT (secret)
|
|||||||
|
|
||||||
import PostgREST.Config (AppConfig(..))
|
import PostgREST.Config (AppConfig(..))
|
||||||
|
|
||||||
dbString :: String
|
testDbConn :: String
|
||||||
dbString = "postgres://postgrest_test_authenticator@localhost:5432/postgrest_test"
|
testDbConn = "postgres://postgrest_test_authenticator@localhost:5432/postgrest_test"
|
||||||
|
|
||||||
cfg :: String -> Maybe Integer -> AppConfig
|
testCfg :: AppConfig
|
||||||
cfg conStr = AppConfig conStr "postgrest_test_anonymous" "test" 3000 (secret "safe") 10
|
testCfg =
|
||||||
|
AppConfig testDbConn "postgrest_test_anonymous" "test" 3000 (secret "safe") 10 Nothing True
|
||||||
cfgDefault :: AppConfig
|
|
||||||
cfgDefault = cfg dbString Nothing
|
|
||||||
|
|
||||||
cfgLimitRows :: Integer -> AppConfig
|
|
||||||
cfgLimitRows = cfg dbString . Just
|
|
||||||
|
|
||||||
setupDb :: IO ()
|
setupDb :: IO ()
|
||||||
setupDb = do
|
setupDb = do
|
||||||
|
|||||||
Reference in New Issue
Block a user