Skip to content

Commit

Permalink
remove config files and hardcode the content
Browse files Browse the repository at this point in the history
  • Loading branch information
Cmdv committed Sep 17, 2024
1 parent d11aaff commit 6010aff
Show file tree
Hide file tree
Showing 13 changed files with 690 additions and 1,442 deletions.
20 changes: 8 additions & 12 deletions cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module Test.Cardano.Db.Mock.Config (
getPoolLayer,
mkConfig,
mkSyncNodeConfig,
mkCustomSyncNodeConfig,
mkConfigDir,
mkFingerPrint,
mkMutableDir,
Expand Down Expand Up @@ -243,11 +242,6 @@ mkSyncNodeConfig configFilePath cmdLineArgs =
configFilename = claConfigFilename cmdLineArgs
configDir = mkConfigDir configFilePath

mkCustomSyncNodeConfig :: FilePath -> CommandLineArgs -> (SyncNodeConfig -> SyncNodeConfig) -> IO SyncNodeConfig
mkCustomSyncNodeConfig cfgDir args updateFn = do
initConfigFile <- mkSyncNodeConfig cfgDir args
pure $ updateFn initConfigFile

mkShelleyCredentials :: FilePath -> IO [ShelleyLeaderCredentials StandardCrypto]
mkShelleyCredentials bulkFile = do
eitherM (panic . textShow) pure $ runExceptT $ readLeaderCredentials (Just protFiles)
Expand Down Expand Up @@ -383,7 +377,7 @@ withFullConfigAndLogs =
withCustomConfig ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -404,7 +398,7 @@ withCustomConfig =
withCustomConfigAndDropDB ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -426,7 +420,7 @@ withCustomConfigAndDropDB =
withCustomConfigAndLogs ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -447,7 +441,7 @@ withCustomConfigAndLogs =
withCustomConfigAndLogsAndDropDB ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -469,7 +463,7 @@ withFullConfig' ::
WithConfigArgs ->
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -483,7 +477,9 @@ withFullConfig' WithConfigArgs {..} cmdLineArgs mSyncNodeConfig configFilePath t
-- check if custom syncNodeConfigs have been passed or not
syncNodeConfig <-
case mSyncNodeConfig of
Just snc -> pure snc
Just updateFn -> do
initConfigFile <- mkSyncNodeConfig configFilePath cmdLineArgs
pure $ updateFn initConfigFile
Nothing -> mkSyncNodeConfig configFilePath cmdLineArgs

cfg <- mkConfig configFilePath mutableDir cmdLineArgs syncNodeConfig
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ import Test.Cardano.Db.Mock.Validate
import Test.Tasty.HUnit (Assertion ())

configRemoveJsonbFromSchemaEnabled :: IOManager -> [(Text, Text)] -> Assertion
configRemoveJsonbFromSchemaEnabled ioManager metadata = do
syncNodeConfig <- mkCustomSyncNodeConfig cfgDir args config
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
configRemoveJsonbFromSchemaEnabled = do
withCustomConfigAndDropDB args (Just config) cfgDir testLabel $ \_interpreter _mockServer dbSync -> do
startDBSync dbSync
threadDelay 7_000_000
assertEqQuery
dbSync
DB.queryJsonbInSchemaExists
False
"There should be no jsonb data types in database if option is enabled"
checkStillRuns dbSync
where
action _interpreter _mockServer dbSync = do
startDBSync dbSync
threadDelay 7_000_000
assertEqQuery
dbSync
DB.queryJsonbInSchemaExists
False
"There should be no jsonb data types in database if option is enabled"
checkStillRuns dbSync

args = initCommandLineArgs {claFullMode = False}
testLabel = "conwayConfigRemoveJsonbFromSchemaEnabled"

Expand All @@ -41,11 +38,9 @@ configRemoveJsonbFromSchemaEnabled ioManager metadata = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig True}}

configRemoveJsonbFromSchemaDisabled :: IOManager -> [(Text, Text)] -> Assertion
configRemoveJsonbFromSchemaDisabled ioManager metadata = do
syncNodeConfig <- mkCustomSyncNodeConfig cfgDir args config
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
where
action _interpreter _mockServer dbSync = do
configRemoveJsonbFromSchemaDisabled = do
withCustomConfigAndDropDB args (Just config) cfgDir testLabel $
\_interpreter _mockServer dbSync -> do
startDBSync dbSync
threadDelay 7_000_000
assertEqQuery
Expand All @@ -54,48 +49,46 @@ configRemoveJsonbFromSchemaDisabled ioManager metadata = do
True
"There should be jsonb types in database if option is disabled"
checkStillRuns dbSync

where
args = initCommandLineArgs {claFullMode = False}
testLabel = "conwayConfigRemoveJsonbFromSchemaDisabled"
cfgDir = conwayConfigDir

config :: SyncNodeConfig -> SyncNodeConfig
config cfg =
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False}}

configJsonbInSchemaShouldRemoveThenAdd :: IOManager -> [(Text, Text)] -> Assertion
configJsonbInSchemaShouldRemoveThenAdd ioManager metadata = do
syncNodeConfig <- mkCustomSyncNodeConfig cfgDir args config
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
configJsonbInSchemaShouldRemoveThenAdd =
withCustomConfigAndDropDB args (Just config) cfgDir testLabel $ \_interpreter _mockServer dbSyncEnv -> do
startDBSync dbSyncEnv
threadDelay 7_000_000
assertEqQuery
dbSyncEnv
DB.queryJsonbInSchemaExists
False
"There should be no jsonb types in database if option has been enabled"
stopDBSync dbSyncEnv
let newDbSyncEnv =
dbSyncEnv
{ dbSyncConfig =
(dbSyncConfig dbSyncEnv)
{ dncInsertOptions =
(dncInsertOptions $ dbSyncConfig dbSyncEnv)
{ sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
}
}
}
startDBSync newDbSyncEnv
threadDelay 7_000_000
assertEqQuery
dbSyncEnv
DB.queryJsonbInSchemaExists
True
"There should be jsonb types in database if option has been disabled"
-- Expected to fail
checkStillRuns dbSyncEnv
where
action _interpreter _mockServer dbSyncEnv = do
startDBSync dbSyncEnv
threadDelay 7_000_000
assertEqQuery
dbSyncEnv
DB.queryJsonbInSchemaExists
False
"There should be no jsonb types in database if option has been enabled"
stopDBSync dbSyncEnv
let newDbSyncEnv =
dbSyncEnv
{ dbSyncConfig =
(dbSyncConfig dbSyncEnv)
{ dncInsertOptions =
(dncInsertOptions $ dbSyncConfig dbSyncEnv)
{ sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
}
}
}
startDBSync newDbSyncEnv
threadDelay 7_000_000
assertEqQuery
dbSyncEnv
DB.queryJsonbInSchemaExists
True
"There should be jsonb types in database if option has been disabled"
-- Expected to fail
checkStillRuns dbSyncEnv

args = initCommandLineArgs {claFullMode = False}
testLabel = "configJsonbInSchemaShouldRemoveThenAdd"
cfgDir = conwayConfigDir
Expand Down
Loading

0 comments on commit 6010aff

Please sign in to comment.