Reduce test settings duplication
and better variable name
This commit is contained in:
+11
-7
@@ -39,18 +39,22 @@ isLeft _ = False
|
|||||||
cfg :: AppConfig
|
cfg :: AppConfig
|
||||||
cfg = AppConfig "postgrest_test" 5432 "postgrest_test" "" "localhost" 3000 "postgrest_anonymous" False 10
|
cfg = AppConfig "postgrest_test" 5432 "postgrest_test" "" "localhost" 3000 "postgrest_anonymous" False 10
|
||||||
|
|
||||||
testSettings :: PoolSettings
|
testPoolOpts :: PoolSettings
|
||||||
testSettings = fromMaybe (error "bad settings") $ H.poolSettings 1 30
|
testPoolOpts = fromMaybe (error "bad settings") $ H.poolSettings 1 30
|
||||||
|
|
||||||
pgSettings :: H.Settings
|
pgSettings :: H.Settings
|
||||||
pgSettings = H.ParamSettings "localhost" 5432 "postgrest_test" "" "postgrest_test"
|
pgSettings = H.ParamSettings (cs $ configDbHost cfg)
|
||||||
|
(fromIntegral $ configDbPort cfg)
|
||||||
|
(cs $ configDbUser cfg)
|
||||||
|
(cs $ configDbPass cfg)
|
||||||
|
(cs $ configDbName cfg)
|
||||||
|
|
||||||
withApp :: ActionWith Application -> IO ()
|
withApp :: ActionWith Application -> IO ()
|
||||||
withApp perform = do
|
withApp perform = do
|
||||||
let anonRole = cs $ configAnonRole cfg
|
let anonRole = cs $ configAnonRole cfg
|
||||||
currRole = cs $ configDbUser cfg
|
currRole = cs $ configDbUser cfg
|
||||||
pool :: H.Pool H.Postgres
|
pool :: H.Pool H.Postgres
|
||||||
<- H.acquirePool pgSettings testSettings
|
<- H.acquirePool pgSettings testPoolOpts
|
||||||
|
|
||||||
perform $ middle $ \req resp -> do
|
perform $ middle $ \req resp -> do
|
||||||
body <- strictRequestBody req
|
body <- strictRequestBody req
|
||||||
@@ -64,7 +68,7 @@ withApp perform = do
|
|||||||
resetDb :: IO ()
|
resetDb :: IO ()
|
||||||
resetDb = do
|
resetDb = do
|
||||||
pool :: H.Pool H.Postgres
|
pool :: H.Pool H.Postgres
|
||||||
<- H.acquirePool pgSettings testSettings
|
<- H.acquirePool pgSettings testPoolOpts
|
||||||
void . liftIO $ H.session pool $
|
void . liftIO $ H.session pool $
|
||||||
H.tx Nothing $ do
|
H.tx Nothing $ do
|
||||||
H.unitEx [H.stmt| drop schema if exists "1" cascade |]
|
H.unitEx [H.stmt| drop schema if exists "1" cascade |]
|
||||||
@@ -97,14 +101,14 @@ authHeader u p =
|
|||||||
clearTable :: Text -> IO ()
|
clearTable :: Text -> IO ()
|
||||||
clearTable table = do
|
clearTable table = do
|
||||||
pool :: H.Pool H.Postgres
|
pool :: H.Pool H.Postgres
|
||||||
<- H.acquirePool pgSettings testSettings
|
<- H.acquirePool pgSettings testPoolOpts
|
||||||
void . liftIO $ H.session pool $ H.tx Nothing $
|
void . liftIO $ H.session pool $ H.tx Nothing $
|
||||||
H.unitEx $ H.Stmt ("delete from \"1\"."<>table) V.empty True
|
H.unitEx $ H.Stmt ("delete from \"1\"."<>table) V.empty True
|
||||||
|
|
||||||
createItems :: Int -> IO ()
|
createItems :: Int -> IO ()
|
||||||
createItems n = do
|
createItems n = do
|
||||||
pool :: H.Pool H.Postgres
|
pool :: H.Pool H.Postgres
|
||||||
<- H.acquirePool pgSettings testSettings
|
<- H.acquirePool pgSettings testPoolOpts
|
||||||
void . liftIO $ H.session pool $ H.tx Nothing txn
|
void . liftIO $ H.session pool $ H.tx Nothing txn
|
||||||
where
|
where
|
||||||
txn = sequence_ $ map H.unitEx stmts
|
txn = sequence_ $ map H.unitEx stmts
|
||||||
|
|||||||
Reference in New Issue
Block a user