mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 13:02:11 +03:00
dc4a286c64
## Description This PR adds all the scaffolding for tests that require remote servers. It is mostly a refactor of `Feature`; where we listed for each test a list of individual backends, we now provide a list of `Context`s, that allows for tests to specify not only how it should be setup, but also what state needs to be carried around throughout the test. This will be useful when launching custom remote servers. Additionally, this PR: - cleans the way we generate logs in the engine as part of the tests - cleans the cabal file - introduce a few more helpers for sending commands to the engine (such as `postMetadata_`) - allows for headers in queries sent to the engine (to support permissions tests) - adds basic code to start / stop a "remote" server This PR is a pre-requisite of #3567. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3573 Co-authored-by: jkachmar <8461423+jkachmar@users.noreply.github.com> GitOrigin-RevId: 05f808c6b85729dbb3ea6648c3e10a3c16b641ef
44 lines
1.2 KiB
Haskell
44 lines
1.2 KiB
Haskell
-- | State shared by tests. We intentionally use an abstract type to
|
|
-- wrap up the values we need for tests, with accessors. This way, the
|
|
-- tests are less liable to refactorings when we add or change the
|
|
-- state.
|
|
module Harness.State
|
|
( State (..),
|
|
Server (..),
|
|
getServer,
|
|
serverUrl,
|
|
)
|
|
where
|
|
|
|
import Control.Concurrent
|
|
import Data.Word
|
|
import Hasura.Prelude hiding (State)
|
|
|
|
-- | A state that's passed to all tests.
|
|
data State = State
|
|
{ server :: Server
|
|
}
|
|
|
|
-- | Information about a server that we're working with.
|
|
data Server = Server
|
|
{ -- | The port to connect on.
|
|
port :: Word16,
|
|
-- | The full URI prefix e.g. http://localhost
|
|
urlPrefix :: String,
|
|
-- | The thread that the server is running on, so we can stop it later.
|
|
threadId :: ThreadId
|
|
}
|
|
|
|
-- | Retrieve the 'Server' associated with some 'State'.
|
|
getServer :: State -> Server
|
|
getServer State {server} = server
|
|
|
|
-- | Extracts the full URL prefix and port number from a given 'Server'.
|
|
--
|
|
-- @
|
|
-- > serverUrl (Server 8080 "http://localhost" someThreadId)
|
|
-- "http://localhost:8080"
|
|
-- @
|
|
serverUrl :: Server -> String
|
|
serverUrl Server {urlPrefix, port} = urlPrefix ++ ":" ++ show port
|