Skip to content

Commit

Permalink
cardano-node | tests: internal/external subdir resolution for new
Browse files Browse the repository at this point in the history
tracing
  • Loading branch information
jutaro authored and mgmeier committed Dec 13, 2024
1 parent 437f2db commit 2146f13
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
60 changes: 34 additions & 26 deletions cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
1 change: 1 addition & 0 deletions configuration/cardano/update-config-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions nix/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2146f13

Please sign in to comment.