2023-06-23 08:14:16 +00:00
|
|
|
|
using DistTestCore.Codex;
|
|
|
|
|
using Newtonsoft.Json;
|
2023-06-21 06:28:40 +00:00
|
|
|
|
|
|
|
|
|
namespace ContinuousTests
|
|
|
|
|
{
|
|
|
|
|
public class Configuration
|
|
|
|
|
{
|
|
|
|
|
public string LogPath { get; set; } = string.Empty;
|
2023-06-25 07:53:10 +00:00
|
|
|
|
public string DataPath { get; set; } = string.Empty;
|
2023-06-23 08:14:16 +00:00
|
|
|
|
public CodexDeployment CodexDeployment { get; set; } = null!;
|
2023-06-21 09:01:48 +00:00
|
|
|
|
public bool KeepPassedTestLogs { get; set; }
|
2023-06-21 06:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ConfigLoader
|
|
|
|
|
{
|
|
|
|
|
private const string filename = "config.json";
|
|
|
|
|
|
|
|
|
|
public Configuration Load()
|
|
|
|
|
{
|
|
|
|
|
var config = Read();
|
2023-06-21 08:06:54 +00:00
|
|
|
|
|
2023-06-21 06:28:40 +00:00
|
|
|
|
Validate(config);
|
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Configuration Read()
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(filename))
|
|
|
|
|
{
|
|
|
|
|
var lines = File.ReadAllText(filename);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = JsonConvert.DeserializeObject<Configuration>(lines);
|
|
|
|
|
if (result != null) return result;
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-26 11:58:41 +00:00
|
|
|
|
var logPath = "logs";// Environment.GetEnvironmentVariable("LOGPATH");
|
|
|
|
|
var dataPath = "data";// Environment.GetEnvironmentVariable("DATAPATH");
|
|
|
|
|
var codexDeploymentJson = "C:\\Users\\Ben\\Desktop\\codex-deployment.json"; // Environment.GetEnvironmentVariable("CODEXDEPLOYMENT");
|
2023-06-25 08:50:01 +00:00
|
|
|
|
var keep = Environment.GetEnvironmentVariable("KEEPPASSEDTESTLOGS");
|
2023-06-21 06:28:40 +00:00
|
|
|
|
|
2023-06-21 08:34:29 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(logPath) &&
|
2023-06-25 08:50:01 +00:00
|
|
|
|
!string.IsNullOrEmpty(dataPath) &&
|
|
|
|
|
!string.IsNullOrEmpty(codexDeploymentJson))
|
2023-06-21 06:28:40 +00:00
|
|
|
|
{
|
2023-06-23 08:14:16 +00:00
|
|
|
|
try
|
2023-06-21 06:28:40 +00:00
|
|
|
|
{
|
2023-06-23 08:14:16 +00:00
|
|
|
|
return new Configuration
|
|
|
|
|
{
|
|
|
|
|
LogPath = logPath,
|
2023-06-25 08:50:01 +00:00
|
|
|
|
DataPath = dataPath,
|
2023-06-23 08:14:16 +00:00
|
|
|
|
CodexDeployment = ParseCodexDeploymentJson(codexDeploymentJson),
|
|
|
|
|
KeepPassedTestLogs = keep == "1"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Exception: " + ex);
|
2023-06-21 06:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 08:34:29 +00:00
|
|
|
|
var nl = Environment.NewLine;
|
2023-06-21 06:28:40 +00:00
|
|
|
|
throw new Exception($"Unable to load configuration from '{filename}', and " +
|
2023-06-21 09:01:48 +00:00
|
|
|
|
"unable to load configuration from environment variables. " + nl +
|
|
|
|
|
"'LOGPATH' = Path where log files will be saved." + nl +
|
2023-06-25 08:50:01 +00:00
|
|
|
|
"'DATAPATH' = Path where temporary data files will be saved." + nl +
|
2023-06-23 08:14:16 +00:00
|
|
|
|
"'CODEXDEPLOYMENT' = Path to codex-deployment JSON file." + nl +
|
2023-06-21 08:34:29 +00:00
|
|
|
|
nl);
|
2023-06-21 06:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Validate(Configuration configuration)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(configuration.LogPath))
|
|
|
|
|
{
|
2023-06-25 08:50:01 +00:00
|
|
|
|
throw new Exception($"Invalid LogPath set: '{configuration.LogPath}'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(configuration.DataPath))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Invalid DataPath set: '{configuration.DataPath}'");
|
2023-06-21 06:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-23 08:35:23 +00:00
|
|
|
|
if (configuration.CodexDeployment == null || !configuration.CodexDeployment.CodexContainers.Any())
|
2023-06-21 06:28:40 +00:00
|
|
|
|
{
|
2023-06-23 08:14:16 +00:00
|
|
|
|
throw new Exception("No Codex deployment found.");
|
2023-06-21 06:28:40 +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;
|
|
|
|
|
}
|
2023-06-21 06:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|