From 2146f13aad63f1b20b6f60795787c604814b42a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Nicklisch-Franken?= Date: Tue, 10 Dec 2024 18:16:18 +0100 Subject: [PATCH] cardano-node | tests: internal/external subdir resolution for new tracing --- .../Cardano/Tracing/NewTracing/Consistency.hs | 60 +++++++++++-------- configuration/cardano/update-config-files.sh | 1 + nix/haskell.nix | 1 + 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs b/cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs index 94d94e419be..7ff1d998edd 100644 --- a/cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs +++ b/cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs @@ -6,9 +6,9 @@ module Test.Cardano.Tracing.NewTracing.Consistency (tests) where import Cardano.Node.Tracing.Consistency (checkNodeTraceConfiguration) -import Control.Monad.IO.Class (MonadIO, liftIO) +import Control.Monad.IO.Class (MonadIO) import Data.Text -import System.Directory (canonicalizePath) +import qualified System.Directory as IO import System.FilePath (()) import Hedgehog (Property) @@ -22,38 +22,46 @@ tests = do H.checkSequential $ H.Group "Configuration Consistency tests" $ Prelude.map test - [ ( [] - -- This file name shoud reference the current standard config with new tracing + [ ( [] + -- This file name should reference the current standard config with new tracing + , configSubdir , "mainnet-config-new-tracing.json" - , configPrefix) - , ( [] + ) + , + ( [] + , testSubdir , "goodConfig.yaml" - , testPrefix) + ) , ( [ "Config namespace error: Illegal namespace ChainDB.CopyToImmutableDBEvent2.CopiedBlockToImmutableDB" , "Config namespace error: Illegal namespace SubscriptionDNS" ] + , testSubdir , "badConfig.yaml" - , testPrefix) + ) ] where - test (actualValue, goldenBaseName, prefix) = - (PropertyName goldenBaseName, goldenTestJSON actualValue goldenBaseName prefix) - - -goldenTestJSON :: [Text] -> FilePath -> (FilePath -> IO FilePath) -> Property -goldenTestJSON expectedOutcome goldenFileBaseName prefixFunc = - H.withTests 1 $ H.withShrinks 0 $ H.property $ do - basePath <- H.getProjectBase - prefixPath <- liftIO $ prefixFunc basePath - goldenFp <- H.note $ prefixPath goldenFileBaseName - actualValue <- liftIO $ checkNodeTraceConfiguration goldenFp - actualValue H.=== expectedOutcome + test (actualValue, subDir, goldenBaseName) = + (PropertyName goldenBaseName, goldenTestJSON subDir actualValue goldenBaseName) +goldenTestJSON :: SubdirSelection -> [Text] -> FilePath -> Property +goldenTestJSON subDir expectedOutcome goldenFileBaseName = + H.withTests 1 $ H.withShrinks 0 $ H.property $ do + base <- resolveDir + goldenFp <- H.note $ base goldenFileBaseName + actualValue <- H.evalIO $ checkNodeTraceConfiguration goldenFp + actualValue H.=== expectedOutcome + where + resolveDir = case subDir of + ExternalSubdir d -> do + base <- H.evalIO . IO.canonicalizePath =<< H.getProjectBase + pure $ base d + InternalSubdir d -> + pure d -configPrefix :: FilePath -> IO FilePath -configPrefix projectBase = do - base <- canonicalizePath projectBase - return $ base "configuration/cardano" +data SubdirSelection = + InternalSubdir FilePath + | ExternalSubdir FilePath -testPrefix :: FilePath -> IO FilePath -testPrefix _ = pure "test/Test/Cardano/Tracing/NewTracing/data/" +testSubdir, configSubdir :: SubdirSelection +testSubdir = InternalSubdir "test/Test/Cardano/Tracing/NewTracing/data" +configSubdir = ExternalSubdir $ "configuration" "cardano" diff --git a/configuration/cardano/update-config-files.sh b/configuration/cardano/update-config-files.sh index dcb306f3790..a702143ed26 100755 --- a/configuration/cardano/update-config-files.sh +++ b/configuration/cardano/update-config-files.sh @@ -20,6 +20,7 @@ copyFile "mainnet-alonzo-genesis.json" copyFile "mainnet-byron-genesis.json" copyFile "mainnet-conway-genesis.json" copyFile "mainnet-config.json" +copyFile "mainnet-config-new-tracing.json" copyFile "mainnet-shelley-genesis.json" copyFile "mainnet-topology.json" diff --git a/nix/haskell.nix b/nix/haskell.nix index 3a0975211f8..71ee8f37b40 100644 --- a/nix/haskell.nix +++ b/nix/haskell.nix @@ -194,6 +194,7 @@ let mainnetConfigFiles = [ "configuration/cardano/mainnet-config.yaml" "configuration/cardano/mainnet-config.json" + "configuration/cardano/mainnet-config-new-tracing.json" "configuration/cardano/mainnet-byron-genesis.json" "configuration/cardano/mainnet-shelley-genesis.json" "configuration/cardano/mainnet-alonzo-genesis.json"