cs-codex-dist-tests/ContinuousTests/Configuration.cs

48 lines
1.6 KiB
C#
Raw Normal View History

2023-06-26 12:44:21 +00:00
using ArgsUniform;
using DistTestCore.Codex;
2023-06-23 08:14:16 +00:00
using Newtonsoft.Json;
namespace ContinuousTests
{
public class Configuration
{
2023-06-26 12:44:21 +00:00
[Uniform("log-path", "l", "LOGPATH", true, "Path where log files will be written.")]
public string LogPath { get; set; } = "logs";
2023-06-26 12:44:21 +00:00
[Uniform("data-path", "d", "DATAPATH", true, "Path where temporary data files will be written.")]
public string DataPath { get; set; } = "data";
2023-06-26 12:44:21 +00:00
[Uniform("codex-deployment", "c", "CODEXDEPLOYMENT", true, "Path to codex-deployment JSON file.")]
public string CodexDeploymentJson { get; set; } = string.Empty;
2023-06-26 12:44:21 +00:00
[Uniform("keep", "k", "KEEP", false, "Set to '1' to retain logs of successful tests.")]
public bool KeepPassedTestLogs { get; set; } = false;
2023-06-26 13:37:16 +00:00
[Uniform("kube-config", "kc", "KUBECONFIG", true, "Path to Kubeconfig file.")]
public string KubeConfigFile { get; set; } = string.Empty;
2023-06-26 12:44:21 +00:00
public CodexDeployment CodexDeployment { get; set; } = null!;
}
2023-06-26 12:44:21 +00:00
public class ConfigLoader
{
public Configuration Load(string[] args)
{
2023-06-26 12:44:21 +00:00
var uniformArgs = new ArgsUniform<Configuration>(args);
2023-06-25 08:50:01 +00:00
2023-06-26 12:44:21 +00:00
var result = uniformArgs.Parse();
result.CodexDeployment = ParseCodexDeploymentJson(result.CodexDeploymentJson);
2023-06-26 12:44:21 +00:00
return result;
}
2023-06-26 12:44:21 +00:00
2023-06-23 08:14:16 +00: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;
}
}
}