2021-05-26 19:19:26 +03:00
|
|
|
{-# LANGUAGE UndecidableInstances #-}
|
2019-10-21 19:01:05 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
module Main (main) where
|
2020-12-28 15:56:00 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
import Control.Concurrent.MVar
|
|
|
|
import Control.Natural ((:~>) (..))
|
|
|
|
import Data.Aeson qualified as A
|
|
|
|
import Data.ByteString.Lazy.Char8 qualified as BL
|
2021-11-09 17:21:48 +03:00
|
|
|
import Data.ByteString.Lazy.UTF8 qualified as LBS
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Environment qualified as Env
|
|
|
|
import Data.Time.Clock (getCurrentTime)
|
|
|
|
import Data.URL.Template
|
2022-07-18 17:14:08 +03:00
|
|
|
import Database.MSSQL.TransactionSuite qualified as TransactionSuite
|
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
|
|
|
import Database.PG.Query qualified as PG
|
2022-07-18 17:14:08 +03:00
|
|
|
import Discover qualified
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.App
|
|
|
|
( PGMetadataStorageAppT (..),
|
2022-01-04 14:53:50 +03:00
|
|
|
mkMSSQLSourceResolver,
|
2021-09-24 01:56:37 +03:00
|
|
|
mkPgSourceResolver,
|
|
|
|
)
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.Backends.Postgres.Connection.MonadTx
|
|
|
|
import Hasura.Backends.Postgres.Connection.Settings
|
|
|
|
import Hasura.Backends.Postgres.Execute.Types
|
2022-09-15 14:45:14 +03:00
|
|
|
import Hasura.EventTriggerCleanupSuite qualified as EventTriggerCleanupSuite
|
2022-07-14 20:57:28 +03:00
|
|
|
import Hasura.GraphQL.Schema.Options qualified as Options
|
2021-11-09 17:21:48 +03:00
|
|
|
import Hasura.Logging
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Metadata.Class
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.DDL.Schema.Cache
|
|
|
|
import Hasura.RQL.DDL.Schema.Cache.Common
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Common
|
2022-10-20 15:45:31 +03:00
|
|
|
import Hasura.RQL.Types.Metadata (emptyMetadataDefaults)
|
2022-10-20 04:32:54 +03:00
|
|
|
import Hasura.RQL.Types.ResizePool
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.SchemaCache.Build
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Server.Init
|
|
|
|
import Hasura.Server.Migrate
|
2022-07-18 17:14:08 +03:00
|
|
|
import Hasura.Server.MigrateSuite qualified as MigrateSuite
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Server.Types
|
2022-07-18 17:14:08 +03:00
|
|
|
import Hasura.StreamingSubscriptionSuite qualified as StreamingSubscriptionSuite
|
2021-09-24 01:56:37 +03:00
|
|
|
import Network.HTTP.Client qualified as HTTP
|
|
|
|
import Network.HTTP.Client.TLS qualified as HTTP
|
|
|
|
import Options.Applicative
|
|
|
|
import System.Environment (getEnvironment)
|
|
|
|
import System.Exit (exitFailure)
|
|
|
|
import Test.Hspec
|
|
|
|
import Test.Hspec.Runner qualified as Hspec
|
2019-11-18 21:45:54 +03:00
|
|
|
|
|
|
|
data TestSuites
|
2021-09-09 10:59:04 +03:00
|
|
|
= -- | Run all test suites. It probably doesn't make sense to be able to specify additional
|
|
|
|
-- hspec args here.
|
2021-12-06 18:46:52 +03:00
|
|
|
AllSuites
|
2021-09-09 10:59:04 +03:00
|
|
|
| -- | Args to pass through to hspec (as if from 'getArgs'), and the specific suite to run.
|
|
|
|
SingleSuite ![String] !TestSuite
|
2019-11-18 21:45:54 +03:00
|
|
|
|
|
|
|
data TestSuite
|
|
|
|
= UnitSuite
|
2021-12-06 18:46:52 +03:00
|
|
|
| PostgresSuite
|
|
|
|
| MSSQLSuite
|
2019-10-21 19:01:05 +03:00
|
|
|
|
2019-12-14 09:47:38 +03:00
|
|
|
main :: IO ()
|
2022-04-07 17:41:43 +03:00
|
|
|
main = do
|
2021-10-13 19:38:56 +03:00
|
|
|
parseArgs >>= \case
|
2021-12-06 18:46:52 +03:00
|
|
|
AllSuites -> do
|
2022-07-18 17:14:08 +03:00
|
|
|
streamingSubscriptionSuite <- StreamingSubscriptionSuite.buildStreamingSubscriptionSuite
|
2022-09-15 14:45:14 +03:00
|
|
|
eventTriggerLogCleanupSuite <- EventTriggerCleanupSuite.buildEventTriggerCleanupSuite
|
2021-12-06 18:46:52 +03:00
|
|
|
postgresSpecs <- buildPostgresSpecs
|
|
|
|
mssqlSpecs <- buildMSSQLSpecs
|
2022-09-15 14:45:14 +03:00
|
|
|
runHspec [] (Discover.spec *> postgresSpecs *> mssqlSpecs *> streamingSubscriptionSuite *> eventTriggerLogCleanupSuite)
|
2022-04-07 17:41:43 +03:00
|
|
|
SingleSuite hspecArgs suite -> do
|
2021-10-13 19:38:56 +03:00
|
|
|
runHspec hspecArgs =<< case suite of
|
2022-07-18 17:14:08 +03:00
|
|
|
UnitSuite -> pure Discover.spec
|
2021-12-06 18:46:52 +03:00
|
|
|
PostgresSuite -> buildPostgresSpecs
|
|
|
|
MSSQLSuite -> buildMSSQLSpecs
|
2019-11-18 21:45:54 +03:00
|
|
|
|
2022-06-29 16:35:59 +03:00
|
|
|
buildMSSQLSpecs :: IO (SpecWith ())
|
2021-12-06 18:46:52 +03:00
|
|
|
buildMSSQLSpecs = do
|
2021-09-09 10:59:04 +03:00
|
|
|
env <- liftIO getEnvironment
|
2021-12-06 18:46:52 +03:00
|
|
|
connStr <- flip onLeft printErrExit $
|
2021-09-09 10:59:04 +03:00
|
|
|
runWithEnv env $ do
|
|
|
|
let envVar = fst mssqlConnectionString
|
2021-12-06 18:46:52 +03:00
|
|
|
maybeV <- considerEnv envVar
|
2021-09-09 10:59:04 +03:00
|
|
|
onNothing maybeV $
|
|
|
|
throwError $
|
|
|
|
"Expected: " <> envVar
|
2022-07-18 17:14:08 +03:00
|
|
|
|
|
|
|
-- We use "suite" to denote a set of tests that can't (yet) be detected and
|
|
|
|
-- run by @hspec-discover@.
|
|
|
|
pure $ describe "Database.MSSQL.TransactionSuite" $ TransactionSuite.suite connStr
|
2021-09-09 10:59:04 +03:00
|
|
|
|
|
|
|
mssqlConnectionString :: (String, String)
|
|
|
|
mssqlConnectionString =
|
|
|
|
( "HASURA_MSSQL_CONN_STR",
|
2022-10-21 19:23:01 +03:00
|
|
|
"SQL Server database connection string. Example DRIVER={ODBC Driver 18 for SQL Server};SERVER=localhost,1433;Uid=user;Pwd=pass;Encrypt=optional"
|
2021-09-09 10:59:04 +03:00
|
|
|
)
|
|
|
|
|
2021-12-06 18:46:52 +03:00
|
|
|
buildPostgresSpecs :: IO Spec
|
|
|
|
buildPostgresSpecs = do
|
2019-11-18 21:45:54 +03:00
|
|
|
env <- getEnvironment
|
2020-12-28 15:56:00 +03:00
|
|
|
let envMap = Env.mkEnvironment env
|
|
|
|
|
2021-12-06 18:46:52 +03:00
|
|
|
pgUrlText <- flip onLeft printErrExit $
|
2021-09-24 01:56:37 +03:00
|
|
|
runWithEnv env $ do
|
2022-08-05 03:28:49 +03:00
|
|
|
let envVar = _envVar databaseUrlOption
|
2021-12-06 18:46:52 +03:00
|
|
|
maybeV <- considerEnv envVar
|
2021-09-24 01:56:37 +03:00
|
|
|
onNothing maybeV $
|
2022-10-20 15:45:31 +03:00
|
|
|
throwError $
|
|
|
|
"Expected: " <> envVar
|
2019-11-18 21:45:54 +03:00
|
|
|
|
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
|
|
|
let pgConnInfo = PG.ConnInfo 1 $ PG.CDDatabaseURI $ txtToBs pgUrlText
|
2021-12-06 18:46:52 +03:00
|
|
|
urlConf = UrlValue $ InputWebhook $ mkPlainURLTemplate pgUrlText
|
2021-04-28 19:49:23 +03:00
|
|
|
sourceConnInfo =
|
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
|
|
|
PostgresSourceConnInfo urlConf (Just setPostgresPoolSettings) True PG.ReadCommitted Nothing
|
2022-08-10 12:40:57 +03:00
|
|
|
sourceConfig = PostgresConnConfiguration sourceConnInfo Nothing defaultPostgresExtensionsSchema
|
2019-11-18 21:45:54 +03:00
|
|
|
|
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
|
|
|
pgPool <- PG.initPGPool pgConnInfo PG.defaultConnParams {PG.cpConns = 1} print
|
2022-10-17 11:04:54 +03:00
|
|
|
let pgContext = mkPGExecCtx PG.Serializable pgPool NeverResizePool
|
2020-12-28 15:56:00 +03:00
|
|
|
|
2021-11-09 17:21:48 +03:00
|
|
|
logger :: Logger Hasura = Logger $ \l -> do
|
|
|
|
let (logLevel, logType :: EngineLogType Hasura, logDetail) = toEngineLog l
|
|
|
|
t <- liftIO $ getFormattedTime Nothing
|
|
|
|
liftIO $ putStrLn $ LBS.toString $ A.encode $ EngineLog t logLevel logType logDetail
|
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
setupCacheRef = do
|
2019-11-20 21:21:30 +03:00
|
|
|
httpManager <- HTTP.newManager HTTP.tlsManagerSettings
|
2022-09-30 16:24:32 +03:00
|
|
|
let sqlGenCtx =
|
|
|
|
SQLGenCtx
|
|
|
|
Options.Don'tStringifyNumbers
|
|
|
|
Options.Don'tDangerouslyCollapseBooleans
|
|
|
|
Options.Don'tOptimizePermissionFilters
|
|
|
|
Options.EnableBigQueryStringNumericInput
|
2021-02-18 19:46:14 +03:00
|
|
|
maintenanceMode = MaintenanceModeDisabled
|
2021-12-08 09:26:46 +03:00
|
|
|
readOnlyMode = ReadOnlyModeDisabled
|
2021-02-18 19:46:14 +03:00
|
|
|
serverConfigCtx =
|
2022-04-07 17:41:43 +03:00
|
|
|
ServerConfigCtx
|
2022-07-14 20:57:28 +03:00
|
|
|
Options.InferFunctionPermissions
|
|
|
|
Options.DisableRemoteSchemaPermissions
|
2022-04-07 17:41:43 +03:00
|
|
|
sqlGenCtx
|
|
|
|
maintenanceMode
|
|
|
|
mempty
|
|
|
|
EventingEnabled
|
|
|
|
readOnlyMode
|
2022-06-14 12:17:18 +03:00
|
|
|
Nothing -- We are not testing the naming convention here, so defaulting to hasura-default
|
2022-10-20 15:45:31 +03:00
|
|
|
emptyMetadataDefaults
|
2022-01-04 14:53:50 +03:00
|
|
|
cacheBuildParams = CacheBuildParams httpManager (mkPgSourceResolver print) mkMSSQLSourceResolver serverConfigCtx
|
2021-05-26 19:19:26 +03:00
|
|
|
pgLogger = print
|
2019-11-20 21:21:30 +03:00
|
|
|
|
2021-05-26 19:19:26 +03:00
|
|
|
run :: MetadataStorageT (PGMetadataStorageAppT CacheBuild) a -> IO a
|
2020-12-28 15:56:00 +03:00
|
|
|
run =
|
2021-05-26 19:19:26 +03:00
|
|
|
runMetadataStorageT
|
2021-09-24 01:56:37 +03:00
|
|
|
>>> flip runPGMetadataStorageAppT (pgPool, pgLogger)
|
|
|
|
>>> runCacheBuild cacheBuildParams
|
|
|
|
>>> runExceptT
|
|
|
|
>=> flip onLeft printErrJExit
|
|
|
|
>=> flip onLeft printErrJExit
|
2019-11-20 21:21:30 +03:00
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
(metadata, schemaCache) <- run do
|
2021-09-24 01:56:37 +03:00
|
|
|
metadata <-
|
|
|
|
snd
|
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
|
|
|
<$> (liftEitherM . runExceptT . runTx pgContext PG.ReadWrite)
|
2022-08-10 12:40:57 +03:00
|
|
|
(migrateCatalog (Just sourceConfig) defaultPostgresExtensionsSchema maintenanceMode =<< liftIO getCurrentTime)
|
2021-11-09 17:21:48 +03:00
|
|
|
schemaCache <- lift $ lift $ buildRebuildableSchemaCache logger envMap metadata
|
2020-12-28 15:56:00 +03:00
|
|
|
pure (metadata, schemaCache)
|
|
|
|
|
2019-11-20 21:21:30 +03:00
|
|
|
cacheRef <- newMVar schemaCache
|
2022-10-20 15:45:31 +03:00
|
|
|
pure $ NT (run . flip MigrateSuite.runCacheRefT cacheRef . fmap fst . runMetadataT metadata emptyMetadataDefaults)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
2022-07-18 17:14:08 +03:00
|
|
|
-- We use "suite" to denote a set of tests that can't (yet) be detected and
|
|
|
|
-- run by @hspec-discover@.
|
|
|
|
streamingSubscriptionSuite <- StreamingSubscriptionSuite.buildStreamingSubscriptionSuite
|
2022-09-15 14:45:14 +03:00
|
|
|
eventTriggerLogCleanupSuite <- EventTriggerCleanupSuite.buildEventTriggerCleanupSuite
|
2022-04-07 17:41:43 +03:00
|
|
|
|
|
|
|
pure $ do
|
2022-07-18 17:14:08 +03:00
|
|
|
describe "Migrate suite" $
|
2022-04-07 17:41:43 +03:00
|
|
|
beforeAll setupCacheRef $
|
2022-10-20 15:45:31 +03:00
|
|
|
describe "Hasura.Server.Migrate" $
|
|
|
|
MigrateSuite.suite sourceConfig pgContext pgConnInfo
|
2022-07-18 17:14:08 +03:00
|
|
|
describe "Streaming subscription suite" $ streamingSubscriptionSuite
|
2022-09-15 14:45:14 +03:00
|
|
|
describe "Event trigger log cleanup suite" $ eventTriggerLogCleanupSuite
|
2019-11-18 21:45:54 +03:00
|
|
|
|
|
|
|
parseArgs :: IO TestSuites
|
2021-09-24 01:56:37 +03:00
|
|
|
parseArgs =
|
|
|
|
execParser $
|
|
|
|
info (helper <*> (parseNoCommand <|> parseSubCommand)) $
|
|
|
|
fullDesc <> header "Hasura GraphQL Engine test suite"
|
2019-10-21 19:01:05 +03:00
|
|
|
where
|
2021-12-06 18:46:52 +03:00
|
|
|
parseNoCommand = pure AllSuites
|
2020-02-13 20:38:23 +03:00
|
|
|
parseSubCommand = SingleSuite <$> parseHspecPassThroughArgs <*> subCmd
|
|
|
|
where
|
2021-09-09 10:59:04 +03:00
|
|
|
subCmd =
|
|
|
|
subparser $
|
|
|
|
mconcat
|
|
|
|
[ command "unit" $
|
|
|
|
info (pure UnitSuite) $
|
|
|
|
progDesc "Only run unit tests",
|
|
|
|
command "postgres" $
|
2021-12-06 18:46:52 +03:00
|
|
|
info (pure PostgresSuite) $
|
2021-09-09 10:59:04 +03:00
|
|
|
progDesc "Only run Postgres integration tests",
|
|
|
|
command "mssql" $
|
2021-12-06 18:46:52 +03:00
|
|
|
info (pure MSSQLSuite) $
|
2021-09-09 10:59:04 +03:00
|
|
|
progDesc "Only run SQL Server unit tests"
|
|
|
|
]
|
2020-01-21 21:12:27 +03:00
|
|
|
-- Add additional arguments and tweak as needed:
|
|
|
|
hspecArgs = ["match", "skip"]
|
|
|
|
-- parse to a list of arguments as they'd appear from 'getArgs':
|
|
|
|
parseHspecPassThroughArgs :: Parser [String]
|
2021-09-24 01:56:37 +03:00
|
|
|
parseHspecPassThroughArgs = fmap concat $
|
|
|
|
for hspecArgs $ \nm ->
|
|
|
|
fmap (maybe [] (\a -> ["--" <> nm, a])) $
|
|
|
|
optional $
|
|
|
|
strOption
|
|
|
|
( long nm
|
|
|
|
<> metavar "<PATTERN>"
|
|
|
|
<> help "Flag passed through to hspec (see hspec docs)."
|
|
|
|
)
|
2020-01-21 21:12:27 +03:00
|
|
|
|
|
|
|
runHspec :: [String] -> Spec -> IO ()
|
|
|
|
runHspec hspecArgs m = do
|
|
|
|
config <- Hspec.readConfig Hspec.defaultConfig hspecArgs
|
2019-11-18 21:45:54 +03:00
|
|
|
Hspec.evaluateSummary =<< Hspec.runSpec m config
|
|
|
|
|
|
|
|
printErrExit :: String -> IO a
|
|
|
|
printErrExit = (*> exitFailure) . putStrLn
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
|
|
printErrJExit :: (A.ToJSON a) => a -> IO b
|
|
|
|
printErrJExit = (*> exitFailure) . BL.putStrLn . A.encode
|