2022-01-14 00:13:48 +03:00
|
|
|
module SpecHook
|
|
|
|
( hook,
|
2022-06-08 19:35:44 +03:00
|
|
|
setupTestEnvironment,
|
|
|
|
teardownTestEnvironment,
|
2022-01-14 00:13:48 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2022-02-18 16:35:32 +03:00
|
|
|
import Control.Exception.Safe (bracket)
|
2022-03-17 23:53:56 +03:00
|
|
|
import Harness.GraphqlEngine (startServerThread)
|
2022-04-20 20:15:42 +03:00
|
|
|
import Harness.TestEnvironment (TestEnvironment (..), stopServer)
|
2022-08-03 17:18:43 +03:00
|
|
|
import Hasura.Prelude
|
2022-02-18 16:35:32 +03:00
|
|
|
import System.Environment (lookupEnv)
|
2022-08-03 17:18:43 +03:00
|
|
|
import System.Log.FastLogger qualified as FL
|
2022-02-18 16:35:32 +03:00
|
|
|
import Test.Hspec (Spec, SpecWith, aroundAllWith)
|
2022-01-14 00:13:48 +03:00
|
|
|
|
2022-04-20 20:15:42 +03:00
|
|
|
setupTestEnvironment :: IO TestEnvironment
|
|
|
|
setupTestEnvironment = do
|
2022-01-14 00:13:48 +03:00
|
|
|
murlPrefix <- lookupEnv "HASURA_TEST_URLPREFIX"
|
|
|
|
mport <- fmap (>>= readMaybe) (lookupEnv "HASURA_TEST_PORT")
|
|
|
|
server <- startServerThread ((,) <$> murlPrefix <*> mport)
|
2022-08-03 17:18:43 +03:00
|
|
|
let logType = FL.LogFileNoRotate "tests-hspec.log" 1024
|
|
|
|
(logger, loggerCleanup) <- FL.newFastLogger logType
|
|
|
|
pure TestEnvironment {..}
|
2022-01-14 00:13:48 +03:00
|
|
|
|
2022-04-20 20:15:42 +03:00
|
|
|
teardownTestEnvironment :: TestEnvironment -> IO ()
|
2022-08-03 17:18:43 +03:00
|
|
|
teardownTestEnvironment TestEnvironment {..} = do
|
2022-01-14 00:13:48 +03:00
|
|
|
stopServer server
|
2022-08-03 17:18:43 +03:00
|
|
|
loggerCleanup
|
2022-01-14 00:13:48 +03:00
|
|
|
|
2022-04-20 20:15:42 +03:00
|
|
|
hook :: SpecWith TestEnvironment -> Spec
|
|
|
|
hook = aroundAllWith (const . bracket setupTestEnvironment teardownTestEnvironment)
|