graphql-engine/server/tests-hspec/SpecHook.hs
Sibi Prabakaran e43a5e4794 Rename State to TestEnvironment in hspec test suite
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4309
GitOrigin-RevId: 899b1aa3674654f5c4bdf94dcd45009570b34644
2022-04-20 17:16:42 +00:00

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)