Refactor/extract pro arg parser and add tests

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5142
GitOrigin-RevId: 724d5ad0e3f66fb5ba79f48946426ad4eddee37d
This commit is contained in:
Solomon 2022-07-21 16:35:50 -07:00 committed by hasura-bot
parent 4c1c69b339
commit 0109dd7fd4
2 changed files with 18 additions and 6 deletions

View File

@ -8,6 +8,9 @@ module Hasura.Server.Init.Config
HGECommand (..),
HGEOptions (..),
HGEOptionsRaw (..),
horDatabaseUrl,
horMetadataDbUrl,
horCommand,
KeepAliveDelay (..),
OptionalInterval (..),
PostgresConnInfo (..),
@ -363,11 +366,20 @@ data HGECommand a
-- | HGE Options from the arg parser and the env.
data HGEOptionsRaw impl = HGEOptionsRaw
{ horDatabaseUrl :: !(PostgresConnInfo (Maybe PostgresRawConnInfo)),
horMetadataDbUrl :: !(Maybe String),
horCommand :: !(HGECommand impl)
{ _horDatabaseUrl :: !(PostgresConnInfo (Maybe PostgresRawConnInfo)),
_horMetadataDbUrl :: !(Maybe String),
_horCommand :: !(HGECommand impl)
}
horDatabaseUrl :: Lens' (HGEOptionsRaw impl) (PostgresConnInfo (Maybe PostgresRawConnInfo))
horDatabaseUrl = lens _horDatabaseUrl $ \hdu a -> hdu {_horDatabaseUrl = a}
horMetadataDbUrl :: Lens' (HGEOptionsRaw impl) (Maybe String)
horMetadataDbUrl = lens _horMetadataDbUrl $ \hdu a -> hdu {_horMetadataDbUrl = a}
horCommand :: Lens' (HGEOptionsRaw impl) (HGECommand impl)
horCommand = lens _horCommand $ \hdu a -> hdu {_horCommand = a}
-- | The final processed HGE options.
data HGEOptions impl = HGEOptions
{ hoDatabaseUrl :: !(PostgresConnInfo (Maybe UrlConf)),

View File

@ -69,7 +69,7 @@ mainParserSpec =
-- Then
result = Opt.execParserPure Opt.defaultPrefs parserInfo argInput
fmap (preview (UUT.pciDatabaseConn . _Just . UUT._PGConnDatabaseUrl) . UUT.horDatabaseUrl) result `Hspec.shouldSatisfy` \case
fmap (preview (UUT.horDatabaseUrl . UUT.pciDatabaseConn . _Just . UUT._PGConnDatabaseUrl)) result `Hspec.shouldSatisfy` \case
Opt.Success template -> template == eitherToMaybe (Template.parseURLTemplate "https://hasura.io/{{foo}}")
Opt.Failure _pf -> False
Opt.CompletionInvoked _cr -> False
@ -96,7 +96,7 @@ mainParserSpec =
-- Then
result = Opt.execParserPure Opt.defaultPrefs parserInfo argInput
fmap (preview (UUT.pciDatabaseConn . _Just . UUT._PGConnDetails) . UUT.horDatabaseUrl) result `Hspec.shouldSatisfy` \case
fmap (preview (UUT.horDatabaseUrl . UUT.pciDatabaseConn . _Just . UUT._PGConnDetails)) result `Hspec.shouldSatisfy` \case
Opt.Success template ->
template
== Just
@ -120,7 +120,7 @@ mainParserSpec =
-- Then
result = Opt.execParserPure Opt.defaultPrefs parserInfo argInput
fmap UUT.horMetadataDbUrl result `Hspec.shouldSatisfy` \case
fmap UUT._horMetadataDbUrl result `Hspec.shouldSatisfy` \case
Opt.Success metadataUrl -> metadataUrl == Just "postgres://user:password@localhost/hasura"
Opt.Failure _pf -> False
Opt.CompletionInvoked _cr -> False