graphql-engine/server/tests-hspec/Harness/State.hs
Antoine Leblanc ccea1da1d5 Enable and test remote relationships from remote schemas.
### Description

This is it! This PR enables the Metadata API for remote relationships from remote schemas, adds tests, ~~adds documentation~~, adds an entry to the Changelog. This is the release PR that enables the feature.

### Checklist
- [ ] Tests:
  - [x] RS-to-Postgres (high level)
  - [x] RS-to-RS (high level)
  - [x] From RS specifically (testing for edge cases)
  - [x] Metadata API tests
  - [ ] Unit testing the actual engine?
- [x] Changelog entry
- [ ] Documentation?

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3974
Co-authored-by: Vamshi Surabhi <6562944+0x777@users.noreply.github.com>
Co-authored-by: Vishnu Bharathi <4211715+scriptnull@users.noreply.github.com>
Co-authored-by: jkachmar <8461423+jkachmar@users.noreply.github.com>
GitOrigin-RevId: c9aebf12e6eebef8d264ea831a327b968d4be9d2
2022-03-17 20:54:57 +00:00

49 lines
1.3 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,
stopServer,
)
where
import Control.Concurrent (ThreadId, killThread)
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
-- | Forcibly stop a given 'Server'.
stopServer :: Server -> IO ()
stopServer Server {threadId} = killThread threadId