2023-06-26 14:44:21 +02:00
using ArgsUniform ;
2023-09-20 13:33:58 +02:00
using CodexPlugin ;
2023-06-23 10:14:16 +02:00
using Newtonsoft.Json ;
2023-06-21 08:28:40 +02:00
namespace ContinuousTests
{
public class Configuration
{
2023-06-26 14:44:21 +02:00
[Uniform("log-path", "l", "LOGPATH", true, "Path where log files will be written.")]
public string LogPath { get ; set ; } = "logs" ;
2023-06-21 08:28:40 +02:00
2023-06-26 14:44:21 +02:00
[Uniform("data-path", "d", "DATAPATH", true, "Path where temporary data files will be written.")]
public string DataPath { get ; set ; } = "data" ;
2023-06-21 08:28:40 +02:00
2023-06-26 14:44:21 +02:00
[Uniform("codex-deployment", "c", "CODEXDEPLOYMENT", true, "Path to codex-deployment JSON file.")]
public string CodexDeploymentJson { get ; set ; } = string . Empty ;
2023-06-21 08:28:40 +02:00
2023-10-04 09:19:45 +02:00
[Uniform("keep", "k", "KEEP", false, "Set to 1 or 'true' to retain logs of successful tests.")]
2023-06-26 14:44:21 +02:00
public bool KeepPassedTestLogs { get ; set ; } = false ;
2023-06-21 08:28:40 +02:00
2023-06-27 10:16:59 +02:00
[Uniform("kube-config", "kc", "KUBECONFIG", true, "Path to Kubeconfig file. Use 'null' (default) to use local cluster.")]
public string KubeConfigFile { get ; set ; } = "null" ;
2023-06-26 15:37:16 +02:00
2023-08-30 09:23:13 +02:00
[Uniform("stop", "s", "STOPONFAIL", false, "If greater than zero, runner will stop after this many test failures and download all cluster container logs. 0 by default.")]
public int StopOnFailure { get ; set ; } = 0 ;
2023-06-30 09:09:59 +02:00
2023-09-27 11:33:54 +02:00
[Uniform("target-duration", "td", "TARGETDURATION", false, "If greater than zero, runner will run for this many seconds before stopping.")]
public int TargetDurationSeconds { get ; set ; } = 0 ;
2023-10-03 09:53:02 +02:00
[Uniform("filter", "f", "FILTER", false, "If set, runs only tests whose names contain any of the filter strings. Comma-separated. Case sensitive.")]
public string Filter { get ; set ; } = string . Empty ;
2023-10-04 09:19:45 +02:00
[Uniform("cleanup", "cl", "CLEANUP", false, "If set to 1 or 'true', the kubernetes namespace will be deleted after the test run has finished.")]
2023-10-03 09:53:02 +02:00
public bool Cleanup { get ; set ; } = false ;
2023-06-26 14:44:21 +02:00
public CodexDeployment CodexDeployment { get ; set ; } = null ! ;
}
2023-06-21 08:28:40 +02:00
2023-06-26 14:44:21 +02:00
public class ConfigLoader
{
public Configuration Load ( string [ ] args )
2023-06-21 08:28:40 +02:00
{
2023-06-30 09:09:59 +02:00
var uniformArgs = new ArgsUniform < Configuration > ( PrintHelp , args ) ;
2023-06-25 10:50:01 +02:00
2023-06-27 10:16:59 +02:00
var result = uniformArgs . Parse ( true ) ;
2023-06-26 14:44:21 +02:00
result . CodexDeployment = ParseCodexDeploymentJson ( result . CodexDeploymentJson ) ;
return result ;
2023-06-21 08:28:40 +02:00
}
2023-06-26 14:44:21 +02:00
2023-06-23 10:14:16 +02:00
private CodexDeployment ParseCodexDeploymentJson ( string filename )
{
var d = JsonConvert . DeserializeObject < CodexDeployment > ( File . ReadAllText ( filename ) ) ! ;
if ( d = = null ) throw new Exception ( "Unable to parse " + filename ) ;
return d ;
}
2023-06-30 09:09:59 +02:00
private static void PrintHelp ( )
{
var nl = Environment . NewLine ;
2023-07-18 09:47:44 +02:00
Console . WriteLine ( "ContinuousTests will run a set of tests against a codex deployment given a codex-deployment.json file." + nl +
2023-09-29 10:19:59 +02:00
"The tests will run in an endless loop unless otherwise specified." + nl ) ;
2023-06-30 09:09:59 +02:00
}
2023-06-21 08:28:40 +02:00
}
}