Skip to content

Commit ec1b81c

Browse files
jutaromgmeier
authored andcommitted
cardano-node | tests: internal/external subdir resolution for new
tracing
1 parent 437f2db commit ec1b81c

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Cardano.Node.Tracing.Consistency (checkNodeTraceConfiguration)
88

99
import Control.Monad.IO.Class (MonadIO, liftIO)
1010
import Data.Text
11-
import System.Directory (canonicalizePath)
11+
import qualified System.Directory as IO
1212
import System.FilePath ((</>))
1313

1414
import Hedgehog (Property)
@@ -22,38 +22,45 @@ tests = do
2222
H.checkSequential
2323
$ H.Group "Configuration Consistency tests"
2424
$ Prelude.map test
25-
[ ( []
26-
-- This file name shoud reference the current standard config with new tracing
25+
[ ( []
26+
-- This file name should reference the current standard config with new tracing
27+
, configSubdir
2728
, "mainnet-config-new-tracing.json"
28-
, configPrefix)
29-
, ( []
29+
)
30+
,
31+
( []
32+
, testSubdir
3033
, "goodConfig.yaml"
31-
, testPrefix)
34+
)
3235
, ( [ "Config namespace error: Illegal namespace ChainDB.CopyToImmutableDBEvent2.CopiedBlockToImmutableDB"
3336
, "Config namespace error: Illegal namespace SubscriptionDNS"
3437
]
38+
, testSubdir
3539
, "badConfig.yaml"
36-
, testPrefix)
40+
)
3741
]
3842
where
39-
test (actualValue, goldenBaseName, prefix) =
40-
(PropertyName goldenBaseName, goldenTestJSON actualValue goldenBaseName prefix)
43+
test (actualValue, subDir, goldenBaseName) =
44+
(PropertyName goldenBaseName, goldenTestJSON actualValue subDir goldenBaseName)
4145

42-
43-
goldenTestJSON :: [Text] -> FilePath -> (FilePath -> IO FilePath) -> Property
44-
goldenTestJSON expectedOutcome goldenFileBaseName prefixFunc =
46+
goldenTestJSON :: [Text] -> SubdirSelection -> FilePath -> Property
47+
goldenTestJSON expectedOutcome subDir goldenFileBaseName =
4548
H.withTests 1 $ H.withShrinks 0 $ H.property $ do
46-
basePath <- H.getProjectBase
47-
prefixPath <- liftIO $ prefixFunc basePath
48-
goldenFp <- H.note $ prefixPath </> goldenFileBaseName
49+
base <- resolveDir subDir
50+
goldenFp <- H.note $ base </> goldenFileBaseName
4951
actualValue <- liftIO $ checkNodeTraceConfiguration goldenFp
5052
actualValue H.=== expectedOutcome
53+
where
54+
resolveDir (ExternalSubdir d) = do
55+
base <- H.evalIO . IO.canonicalizePath =<< H.getProjectBase
56+
pure $ base </> d
57+
resolveDir (InternalSubdir d) =
58+
pure d
5159

60+
data SubdirSelection =
61+
InternalSubdir FilePath
62+
| ExternalSubdir FilePath
5263

53-
configPrefix :: FilePath -> IO FilePath
54-
configPrefix projectBase = do
55-
base <- canonicalizePath projectBase
56-
return $ base </> "configuration/cardano"
57-
58-
testPrefix :: FilePath -> IO FilePath
59-
testPrefix _ = pure "test/Test/Cardano/Tracing/NewTracing/data/"
64+
testSubdir, configSubdir :: SubdirSelection
65+
testSubdir = InternalSubdir "test/Test/Cardano/Tracing/NewTracing/data"
66+
configSubdir = ExternalSubdir $ "configuration" </> "cardano"

0 commit comments

Comments
 (0)