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 12, 2024
1 parent 437f2db commit b75ff9a
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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)
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"

0 comments on commit b75ff9a

Please sign in to comment.