mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
e43a5e4794
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4309 GitOrigin-RevId: 899b1aa3674654f5c4bdf94dcd45009570b34644
27 lines
850 B
Haskell
27 lines
850 B
Haskell
module SpecHook
|
|
( hook,
|
|
)
|
|
where
|
|
|
|
import Control.Exception.Safe (bracket)
|
|
import Harness.GraphqlEngine (startServerThread)
|
|
import Harness.TestEnvironment (TestEnvironment (..), stopServer)
|
|
import System.Environment (lookupEnv)
|
|
import Test.Hspec (Spec, SpecWith, aroundAllWith)
|
|
import Text.Read (readMaybe)
|
|
import Prelude
|
|
|
|
setupTestEnvironment :: IO TestEnvironment
|
|
setupTestEnvironment = do
|
|
murlPrefix <- lookupEnv "HASURA_TEST_URLPREFIX"
|
|
mport <- fmap (>>= readMaybe) (lookupEnv "HASURA_TEST_PORT")
|
|
server <- startServerThread ((,) <$> murlPrefix <*> mport)
|
|
pure $ TestEnvironment server
|
|
|
|
teardownTestEnvironment :: TestEnvironment -> IO ()
|
|
teardownTestEnvironment TestEnvironment {server} =
|
|
stopServer server
|
|
|
|
hook :: SpecWith TestEnvironment -> Spec
|
|
hook = aroundAllWith (const . bracket setupTestEnvironment teardownTestEnvironment)
|