graphql-engine/server/tests-hspec/Harness/Test/CustomOptions.hs
Daniel Harvey bf91655c30 tests: allow skipping test suites using a Fixture option
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5773
GitOrigin-RevId: 4ff0f18e96313ce5c0ceb5a284e382a70ed0b9b4
2022-09-07 09:17:22 +00:00

55 lines
1.8 KiB
Haskell

-- | Custom test fixture options.
module Harness.Test.CustomOptions
( Options (..),
combineOptions,
defaultOptions,
)
where
import Harness.Exceptions
import Hasura.Prelude
-- | Custom test fixture options.
data Options = Options
{ -- | Whether a given testing fixture should treat numeric values as strings.
--
-- This is primarily a workaround for tests which run BigQuery.
stringifyNumbers :: Bool,
-- | Whether to skip this Fixture
--
-- Useful for implementing tests that we don't want to depend on in CI yet
-- Text is reason for skipping
skipTests :: Maybe Text
}
-- | This function can be used to combine two sets of 'Option's when creating
-- custom composite 'Fixture's.
--
-- NOTE: This function throws an impure exception if the options are
-- irreconcilable.
combineOptions :: HasCallStack => Maybe Options -> Maybe Options -> Maybe Options
combineOptions (Just lhs) (Just rhs) =
let -- 'stringifyNumbers' can only be unified if both sides have the same value.
stringifyNumbers =
if lhsStringify == rhsStringify
then lhsStringify
else reportInconsistency "stringifyNumbers" lhsStringify rhsStringify
skipTests =
if lhsSkip == lhsSkip
then lhsSkip
else reportInconsistency "skipTests" lhsSkip rhsSkip
in Just Options {..}
where
reportInconsistency fieldName lhsValue rhsValue =
error $ "Could not reconcile '" <> fieldName <> "'\n lhs value: " <> show lhsValue <> "\n rhs value: " <> show rhsValue
Options {stringifyNumbers = lhsStringify, skipTests = lhsSkip} = lhs
Options {stringifyNumbers = rhsStringify, skipTests = rhsSkip} = rhs
combineOptions mLhs mRhs = mLhs <|> mRhs
defaultOptions :: Options
defaultOptions =
Options
{ stringifyNumbers = False,
skipTests = Nothing
}