mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-11-11 05:10:51 +03:00
b658df1c43
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4772 Co-authored-by: Gil Mizrahi <8547573+soupi@users.noreply.github.com> GitOrigin-RevId: 5c6c9056952574462d5b309774331a909a7eac6d
32 lines
1.0 KiB
Haskell
32 lines
1.0 KiB
Haskell
module SpecHook
|
|
( hook,
|
|
setupTestEnvironment,
|
|
teardownTestEnvironment,
|
|
)
|
|
where
|
|
|
|
import Control.Exception.Safe (bracket)
|
|
import Harness.GraphqlEngine (startServerThread)
|
|
import Harness.TestEnvironment (TestEnvironment (..), stopServer)
|
|
import Hasura.Prelude
|
|
import System.Environment (lookupEnv)
|
|
import System.Log.FastLogger qualified as FL
|
|
import Test.Hspec (Spec, SpecWith, aroundAllWith)
|
|
|
|
setupTestEnvironment :: IO TestEnvironment
|
|
setupTestEnvironment = do
|
|
murlPrefix <- lookupEnv "HASURA_TEST_URLPREFIX"
|
|
mport <- fmap (>>= readMaybe) (lookupEnv "HASURA_TEST_PORT")
|
|
server <- startServerThread ((,) <$> murlPrefix <*> mport)
|
|
let logType = FL.LogFileNoRotate "tests-hspec.log" 1024
|
|
(logger, loggerCleanup) <- FL.newFastLogger logType
|
|
pure TestEnvironment {..}
|
|
|
|
teardownTestEnvironment :: TestEnvironment -> IO ()
|
|
teardownTestEnvironment TestEnvironment {..} = do
|
|
stopServer server
|
|
loggerCleanup
|
|
|
|
hook :: SpecWith TestEnvironment -> Spec
|
|
hook = aroundAllWith (const . bracket setupTestEnvironment teardownTestEnvironment)
|