-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- [x] add an option to control where test trace logs are written - [x] update justfile to use the new option - [x] refactor code for less duplication ADP-3252
- Loading branch information
Showing
15 changed files
with
302 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,23 @@ | ||
module Main where | ||
|
||
import qualified Options.Applicative as OptParse | ||
import qualified Test.Syd.OptParse as SydTest | ||
|
||
import Cardano.Wallet.Spec | ||
( TestNetworkConfig (..) | ||
, effectsSpec | ||
( effectsSpec | ||
, walletSpec | ||
) | ||
import Data.Tagged | ||
( Tagged (..) | ||
) | ||
import Main.Utf8 | ||
( withUtf8 | ||
) | ||
import Options.Applicative | ||
( Parser | ||
, eitherReader | ||
, execParser | ||
, fullDesc | ||
, help | ||
, helper | ||
, info | ||
, long | ||
, metavar | ||
, option | ||
, progDesc | ||
, short | ||
) | ||
import Path | ||
( Dir | ||
, SomeBase (..) | ||
, parseSomeDir | ||
) | ||
import Path.IO | ||
( AnyPath (makeAbsolute) | ||
import Options | ||
( withTestOptions | ||
) | ||
import Test.Syd | ||
( sydTestWith | ||
) | ||
|
||
main :: IO () | ||
main = withUtf8 do | ||
testNetworkOptions <- | ||
execParser | ||
$ info | ||
(parser <**> helper) | ||
(fullDesc <> progDesc "E2E Wallet test suite") | ||
testNetwork <- testNetworkOptionsToConfig testNetworkOptions | ||
main = withUtf8 $ withTestOptions $ \testNetwork traceConfiguration -> | ||
sydTestWith SydTest.defaultSettings{SydTest.settingRetries = 1} do | ||
effectsSpec | ||
walletSpec testNetwork | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Command line options -------------------------------------------------------- | ||
|
||
data TestNetworkOptions | ||
= TestNetworkOptionManual | ||
| TestNetworkOptionLocal | ||
(Tagged "state" (SomeBase Dir)) | ||
(Tagged "config" (SomeBase Dir)) | ||
| TestNetworkOptionPreprod | ||
(Tagged "state" (SomeBase Dir)) | ||
(Tagged "config" (SomeBase Dir)) | ||
|
||
testNetworkOptionsToConfig :: TestNetworkOptions -> IO TestNetworkConfig | ||
testNetworkOptionsToConfig = \case | ||
TestNetworkOptionManual -> | ||
pure TestNetworkManual | ||
TestNetworkOptionLocal stateDir nodeConfigsDir -> do | ||
absStateDir <- traverse makeDirAbsolute stateDir | ||
absNodeConfigsDir <- traverse makeDirAbsolute nodeConfigsDir | ||
pure (TestNetworkLocal absStateDir absNodeConfigsDir) | ||
TestNetworkOptionPreprod stateDir nodeConfigsDir -> do | ||
absStateDir <- traverse makeDirAbsolute stateDir | ||
absNodeConfigsDir <- traverse makeDirAbsolute nodeConfigsDir | ||
pure (TestNetworkPreprod absStateDir absNodeConfigsDir) | ||
where | ||
makeDirAbsolute = \case | ||
Abs absDir -> pure absDir | ||
Rel relDir -> makeAbsolute relDir | ||
|
||
parser :: Parser TestNetworkOptions | ||
parser = OptParse.subparser $ cmdManual <> cmdLocal <> cmdPreprod | ||
where | ||
cmdManual = | ||
OptParse.command | ||
"manual" | ||
( OptParse.info | ||
(pure TestNetworkOptionManual) | ||
( OptParse.progDesc | ||
"Relies on a node and wallet started manually." | ||
) | ||
) | ||
cmdLocal = | ||
OptParse.command | ||
"local" | ||
( OptParse.info | ||
( TestNetworkOptionLocal | ||
<$> stateDirOption | ||
<*> nodeConfigsDirOption | ||
) | ||
(OptParse.progDesc "Automatically starts a local test cluster.") | ||
) | ||
cmdPreprod = | ||
OptParse.command | ||
"preprod" | ||
( OptParse.info | ||
( TestNetworkOptionPreprod | ||
<$> stateDirOption | ||
<*> nodeConfigsDirOption | ||
) | ||
( OptParse.progDesc | ||
"Automatically starts a preprod node and wallet." | ||
) | ||
) | ||
stateDirOption :: Parser (Tagged "state" (SomeBase Dir)) = | ||
option | ||
(eitherReader (bimap show Tagged . parseSomeDir)) | ||
( long "state-dir" | ||
<> short 's' | ||
<> metavar "STATE_DIR" | ||
<> help | ||
"Absolute or relative directory path \ | ||
\ to save node and wallet state" | ||
) | ||
nodeConfigsDirOption :: Parser (Tagged "config" (SomeBase Dir)) = | ||
option | ||
(eitherReader (bimap show Tagged . parseSomeDir)) | ||
( long "node-configs-dir" | ||
<> short 'c' | ||
<> metavar "NODE_CONFIGS_DIR" | ||
<> help | ||
"Absolute or relative directory path \ | ||
\ to a directory with node configs" | ||
) | ||
walletSpec traceConfiguration testNetwork |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
module Options where | ||
|
||
import qualified Options.Applicative as OptParse | ||
|
||
import Cardano.Wallet.Spec | ||
( TestNetworkConfig (..) | ||
) | ||
import Cardano.Wallet.Spec.Interpreters.Config | ||
( TraceConfiguration (..) | ||
) | ||
import Cardano.Wallet.Spec.Lib.Paths | ||
( SomeDirOf | ||
, makeDirAbsolute | ||
) | ||
import Data.Tagged | ||
( Tagged (..) | ||
) | ||
import Options.Applicative | ||
( Parser | ||
, eitherReader | ||
, help | ||
, long | ||
, metavar | ||
, option | ||
, short | ||
) | ||
import Path | ||
( parseSomeDir | ||
) | ||
|
||
withTestOptions :: (TestNetworkConfig -> TraceConfiguration -> IO b) -> IO b | ||
withTestOptions action = do | ||
TestOptions{..} :: TestOptions <- | ||
OptParse.execParser | ||
$ OptParse.info | ||
(parserTestOptions OptParse.<**> OptParse.helper) | ||
(OptParse.fullDesc <> OptParse.progDesc "E2E Wallet test suite") | ||
testNetwork <- testNetworkOptionsToConfig testNetworkOptions | ||
traceConfiguration <- do | ||
absTraceDir <- | ||
makeDirAbsolute | ||
$ testGlobalOptionsTraceOutput testGlobalOptions | ||
pure $ TraceConfiguration absTraceDir | ||
action testNetwork traceConfiguration | ||
|
||
parserTestOptions :: Parser TestOptions | ||
parserTestOptions = TestOptions <$> parserNetworkOptions <*> parserGlobalOptions | ||
|
||
data TestOptions = TestOptions | ||
{ testNetworkOptions :: TestNetworkOptions | ||
, testGlobalOptions :: TestGlobalOptions | ||
} | ||
|
||
newtype TestGlobalOptions = TestGlobalOptions | ||
{ testGlobalOptionsTraceOutput :: SomeDirOf "tracing-dir" | ||
} | ||
|
||
parserGlobalOptions :: Parser TestGlobalOptions | ||
parserGlobalOptions = TestGlobalOptions <$> traceOutputOption | ||
where | ||
traceOutputOption :: Parser (SomeDirOf "tracing-dir") = | ||
option | ||
(eitherReader (bimap show Tagged . parseSomeDir)) | ||
( long "tracing-dir" | ||
<> short 't' | ||
<> metavar "TRACE_OUTPUT_DIR" | ||
<> help | ||
"Absolute or relative directory path to save trace output" | ||
) | ||
|
||
data TestNetworkOptions | ||
= TestNetworkOptionManual | ||
| TestNetworkOptionLocal (SomeDirOf "state") (SomeDirOf "config") | ||
| TestNetworkOptionPreprod (SomeDirOf "state") (SomeDirOf "config") | ||
|
||
testNetworkOptionsToConfig :: TestNetworkOptions -> IO TestNetworkConfig | ||
testNetworkOptionsToConfig = \case | ||
TestNetworkOptionManual -> | ||
pure TestNetworkManual | ||
TestNetworkOptionLocal stateDir nodeConfigsDir -> do | ||
absStateDir <- makeDirAbsolute stateDir | ||
absNodeConfigsDir <- makeDirAbsolute nodeConfigsDir | ||
pure (TestNetworkLocal absStateDir absNodeConfigsDir) | ||
TestNetworkOptionPreprod stateDir nodeConfigsDir -> do | ||
absStateDir <- makeDirAbsolute stateDir | ||
absNodeConfigsDir <- makeDirAbsolute nodeConfigsDir | ||
pure (TestNetworkPreprod absStateDir absNodeConfigsDir) | ||
|
||
parserNetworkOptions :: Parser TestNetworkOptions | ||
parserNetworkOptions = OptParse.subparser $ cmdManual <> cmdLocal <> cmdPreprod | ||
where | ||
cmdManual = | ||
OptParse.command | ||
"manual" | ||
( OptParse.info | ||
(pure TestNetworkOptionManual) | ||
( OptParse.progDesc | ||
"Relies on a node and wallet started manually." | ||
) | ||
) | ||
cmdLocal = | ||
OptParse.command | ||
"local" | ||
( OptParse.info | ||
( TestNetworkOptionLocal | ||
<$> stateDirOption | ||
<*> nodeConfigsDirOption | ||
) | ||
(OptParse.progDesc "Automatically starts a local test cluster.") | ||
) | ||
cmdPreprod = | ||
OptParse.command | ||
"preprod" | ||
( OptParse.info | ||
( TestNetworkOptionPreprod | ||
<$> stateDirOption | ||
<*> nodeConfigsDirOption | ||
) | ||
( OptParse.progDesc | ||
"Automatically starts a preprod node and wallet." | ||
) | ||
) | ||
stateDirOption :: Parser (SomeDirOf "state") = | ||
option | ||
(eitherReader (bimap show Tagged . parseSomeDir)) | ||
( long "state-dir" | ||
<> short 's' | ||
<> metavar "STATE_DIR" | ||
<> help | ||
"Absolute or relative directory path \ | ||
\ to save node and wallet state" | ||
) | ||
nodeConfigsDirOption :: Parser (SomeDirOf "config") = | ||
option | ||
(eitherReader (bimap show Tagged . parseSomeDir)) | ||
( long "node-configs-dir" | ||
<> short 'c' | ||
<> metavar "NODE_CONFIGS_DIR" | ||
<> help | ||
"Absolute or relative directory path \ | ||
\ to a directory with node configs" | ||
) |
Oops, something went wrong.