tests-hspec - custom finally and readme toc

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3471
GitOrigin-RevId: 4a1477b7e7f175bf7b4c81405747588980c43d7b
This commit is contained in:
Gil Mizrahi 2022-01-26 14:17:17 +02:00 committed by hasura-bot
parent 4cfc1eea59
commit 9d2ac22365
2 changed files with 51 additions and 1 deletions

View File

@ -41,7 +41,7 @@ feature Feature {backends, tests} =
name
( aroundAllWith
( \actionWith state -> do
finally
finallyRethrow
( do
setup state
actionWith state
@ -51,3 +51,33 @@ feature Feature {backends, tests} =
tests
)
)
-- | A custom 'finally' which re-throws exceptions from both the main action and the sequel action.
--
-- The standard 'finally' only re-throws the @sequel@ exception.
finallyRethrow :: IO a -> IO b -> IO a
finallyRethrow a sequel =
mask $ \restore -> do
r <-
catch
(restore a)
( \restoreEx -> do
_ <- sequel `catch` (throwIO . Exceptions restoreEx)
(throwIO restoreEx)
)
_ <- sequel
pure r
-- | Two exceptions
data Exceptions
= Exceptions SomeException SomeException
instance Show Exceptions where
show (Exceptions e1 e2) =
unlines
[ "1. " <> show e1,
"",
"2. " <> show e2
]
instance Exception Exceptions

View File

@ -4,6 +4,19 @@ Graphql-engine integration tests written in Haskell using the [hspec](https://hs
For motivation, rationale, and more, see the [test suite rfc](../../rfcs/hspec-test-suite.md).
**Table of Contents**
- [Running the test suite](#running-the-test-suite)
- [Test suite structure](#test-suite-structure)
- [Harness](#harness)
- [Test](#test)
- [Adding a new test](#adding-a-new-test)
- [Specifying backends](#specifying-backends)
- [Setup action](#setup-action)
- [Teardown action](#teardown-action)
- [Writing tests](#writing-tests)
- [Style guide](#style-guide)
## Running the test suite
1. To run the Haskell integration test suite, we'll first need to start the backends:
@ -55,6 +68,13 @@ For motivation, rationale, and more, see the [test suite rfc](../../rfcs/hspec-t
cabal run tests-hspec -- --help
```
3. The local databases presist even after shutting down docker-compose.
If this is undesirable, delete the databases using the following command:
```sh
docker-compose down --volumes
```
## Test suite structure
### Harness