mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 12:31:52 +03:00
5541ec011e
## Description This PR adds the possibility for hspec tests to start a remote server with a custom schema, using the _morpheus_ library. In addition, it adds: - X-to-DB object relationships tests - X-to-DB array relationships tests - X-to-RS relationships tests For now, all those X are only postgres, but the tests are written in a way that will allow for it to easily be any other DB, or even remote schemas. The actual tests were taken mostly from #3069. To achieve this, this PR heavily refactors the test harness. Most importantly: it generalizes the notion of a `Backend` to a notion of generic `Context`, allowing for contexts that are the unions of two backends, or of a backend and a remote schema. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3567 Co-authored-by: jkachmar <8461423+jkachmar@users.noreply.github.com> GitOrigin-RevId: 623f700ba482743f94d3eaf659e6cfa22cd0dbc9
27 lines
720 B
Haskell
27 lines
720 B
Haskell
module SpecHook
|
|
( hook,
|
|
)
|
|
where
|
|
|
|
import Control.Exception.Safe (bracket)
|
|
import Harness.GraphqlEngine (startServerThread, stopServer)
|
|
import Harness.State (State (..))
|
|
import System.Environment (lookupEnv)
|
|
import Test.Hspec (Spec, SpecWith, aroundAllWith)
|
|
import Text.Read (readMaybe)
|
|
import Prelude
|
|
|
|
setupState :: IO State
|
|
setupState = do
|
|
murlPrefix <- lookupEnv "HASURA_TEST_URLPREFIX"
|
|
mport <- fmap (>>= readMaybe) (lookupEnv "HASURA_TEST_PORT")
|
|
server <- startServerThread ((,) <$> murlPrefix <*> mport)
|
|
pure $ State server
|
|
|
|
teardownState :: State -> IO ()
|
|
teardownState State {server} =
|
|
stopServer server
|
|
|
|
hook :: SpecWith State -> Spec
|
|
hook = aroundAllWith (const . bracket setupState teardownState)
|