Cleanup code in SpecHelper
This commit is contained in:
+3
-15
@@ -31,24 +31,17 @@ import PostgREST.Middleware
|
|||||||
import PostgREST.Error(pgErrResponse)
|
import PostgREST.Error(pgErrResponse)
|
||||||
import PostgREST.DbStructure
|
import PostgREST.DbStructure
|
||||||
|
|
||||||
systemDb :: String
|
|
||||||
systemDb = "postgres://localhost"
|
|
||||||
|
|
||||||
dbString :: String
|
dbString :: String
|
||||||
dbString = "postgres://postgrest_authenticator@localhost:5432/postgrest_test"
|
dbString = "postgres://postgrest_authenticator@localhost:5432/postgrest_test"
|
||||||
|
|
||||||
isLeft :: Either a b -> Bool
|
|
||||||
isLeft (Left _ ) = True
|
|
||||||
isLeft _ = False
|
|
||||||
|
|
||||||
cfg :: String -> Maybe Int -> AppConfig
|
cfg :: String -> Maybe Int -> AppConfig
|
||||||
cfg conStr limit = AppConfig conStr 3000 "postgrest_anonymous" "test" (secret "safe") 10 limit
|
cfg conStr = AppConfig conStr 3000 "postgrest_anonymous" "test" (secret "safe") 10
|
||||||
|
|
||||||
cfgDefault :: AppConfig
|
cfgDefault :: AppConfig
|
||||||
cfgDefault = cfg dbString Nothing
|
cfgDefault = cfg dbString Nothing
|
||||||
|
|
||||||
cfgLimitRows :: Int -> AppConfig
|
cfgLimitRows :: Int -> AppConfig
|
||||||
cfgLimitRows = (cfg dbString) . Just
|
cfgLimitRows = cfg dbString . Just
|
||||||
|
|
||||||
testPoolOpts :: PoolSettings
|
testPoolOpts :: PoolSettings
|
||||||
testPoolOpts = fromMaybe (error "bad settings") $ H.poolSettings 1 30
|
testPoolOpts = fromMaybe (error "bad settings") $ H.poolSettings 1 30
|
||||||
@@ -56,9 +49,6 @@ testPoolOpts = fromMaybe (error "bad settings") $ H.poolSettings 1 30
|
|||||||
pgSettings :: P.Settings
|
pgSettings :: P.Settings
|
||||||
pgSettings = P.StringSettings $ cs dbString
|
pgSettings = P.StringSettings $ cs dbString
|
||||||
|
|
||||||
setupSettings :: P.Settings
|
|
||||||
setupSettings = P.StringSettings $ cs systemDb
|
|
||||||
|
|
||||||
withApp :: AppConfig -> ActionWith Application -> IO ()
|
withApp :: AppConfig -> ActionWith Application -> IO ()
|
||||||
withApp config perform = do
|
withApp config perform = do
|
||||||
pool :: H.Pool P.Postgres
|
pool :: H.Pool P.Postgres
|
||||||
@@ -85,14 +75,12 @@ setupDb = do
|
|||||||
resetDb
|
resetDb
|
||||||
|
|
||||||
resetDb :: IO ()
|
resetDb :: IO ()
|
||||||
resetDb = do
|
resetDb = loadFixture "data"
|
||||||
loadFixture "data"
|
|
||||||
|
|
||||||
loadFixture :: FilePath -> IO()
|
loadFixture :: FilePath -> IO()
|
||||||
loadFixture name =
|
loadFixture name =
|
||||||
void $ readProcess "psql" ["-U", "postgrest_test", "-d", "postgrest_test", "-a", "-f", "test/fixtures/" ++ name ++ ".sql"] []
|
void $ readProcess "psql" ["-U", "postgrest_test", "-d", "postgrest_test", "-a", "-f", "test/fixtures/" ++ name ++ ".sql"] []
|
||||||
|
|
||||||
|
|
||||||
rangeHdrs :: ByteRange -> [Header]
|
rangeHdrs :: ByteRange -> [Header]
|
||||||
rangeHdrs r = [rangeUnit, (hRange, renderByteRange r)]
|
rangeHdrs r = [rangeUnit, (hRange, renderByteRange r)]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user