From b75ff9aa9ec9de1174b1441dc0cde3276447afb7 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 | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 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..f50759dbcdd 100644 --- a/cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs +++ b/cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs @@ -8,7 +8,7 @@ import Cardano.Node.Tracing.Consistency (checkNodeTraceConfiguration) import Control.Monad.IO.Class (MonadIO, liftIO) 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) + test (actualValue, subDir, goldenBaseName) = + (PropertyName goldenBaseName, goldenTestJSON subDir actualValue goldenBaseName) -goldenTestJSON :: [Text] -> FilePath -> (FilePath -> IO FilePath) -> Property -goldenTestJSON expectedOutcome goldenFileBaseName prefixFunc = + +goldenTestJSON :: SubdirSelection -> [Text] -> FilePath -> Property +goldenTestJSON (ExternalSubdir d) expectedOutcome goldenFileBaseName = 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 + base <- H.note =<< H.evalIO . IO.canonicalizePath =<< H.getProjectBase + let goldenFp = base d goldenFileBaseName + actualValue <- liftIO $ checkNodeTraceConfiguration goldenFp + actualValue H.=== expectedOutcome +goldenTestJSON (InternalSubdir d) expectedOutcome goldenFileBaseName = + H.withTests 1 $ H.withShrinks 0 $ H.property $ do + goldenFp <- H.note $ d goldenFileBaseName + actualValue <- liftIO $ checkNodeTraceConfiguration goldenFp actualValue H.=== expectedOutcome +data SubdirSelection = + InternalSubdir FilePath + | ExternalSubdir FilePath -configPrefix :: FilePath -> IO FilePath -configPrefix projectBase = do - base <- canonicalizePath projectBase - return $ base "configuration/cardano" - -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"