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 4dee70f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
58 changes: 34 additions & 24 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,48 @@ 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 =
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

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

Check warning on line 61 in cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs

View workflow job for this annotation

GitHub Actions / build

Suggestion in goldenTestJSON in module Test.Cardano.Tracing.NewTracing.Consistency: Redundant $ ▫︎ Found: "pure $ d" ▫︎ Perhaps: "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

0 comments on commit 4dee70f

Please sign in to comment.