2
0
mirror of synced 2025-01-15 11:04:10 +00:00

82 lines
2.2 KiB
C#
Raw Normal View History

using NUnit.Framework;
2023-03-21 13:20:21 +01:00
namespace CodexDistTestCore
{
[SetUpFixture]
public abstract class DistTest
{
2023-03-22 09:22:18 +01:00
private TestLog log = null!;
private FileManager fileManager = null!;
private K8sManager k8sManager = null!;
[OneTimeSetUp]
public void GlobalSetup()
{
// Previous test run may have been interrupted.
// Begin by cleaning everything up.
2023-03-22 09:22:18 +01:00
log = new TestLog();
fileManager = new FileManager(log);
k8sManager = new K8sManager(log, fileManager);
2023-03-22 09:22:18 +01:00
try
{
k8sManager.DeleteAllResources();
fileManager.DeleteAllTestFiles();
}
catch (Exception ex)
{
GlobalTestFailure.HasFailed = true;
log.Error($"Global setup cleanup failed with: {ex}");
throw;
}
log.Log("Global setup cleanup successful");
}
[SetUp]
public void SetUpDistTest()
{
2023-03-20 10:37:03 +01:00
if (GlobalTestFailure.HasFailed)
{
Assert.Inconclusive("Skip test: Previous test failed during clean up.");
}
else
{
2023-03-22 09:22:18 +01:00
log = new TestLog();
fileManager = new FileManager(log);
k8sManager = new K8sManager(log, fileManager);
2023-03-20 10:37:03 +01:00
}
}
[TearDown]
public void TearDownDistTest()
{
2023-03-20 10:37:03 +01:00
try
{
2023-03-22 09:22:18 +01:00
log.EndTest(k8sManager);
2023-03-20 10:37:03 +01:00
k8sManager.DeleteAllResources();
fileManager.DeleteAllTestFiles();
}
catch (Exception ex)
{
2023-03-22 09:22:18 +01:00
log.Error("Cleanup failed: " + ex.Message);
2023-03-20 10:37:03 +01:00
GlobalTestFailure.HasFailed = true;
}
}
public TestFile GenerateTestFile(ByteSize size)
{
return fileManager.GenerateTestFile(size);
}
2023-03-21 15:17:48 +01:00
public IOfflineCodexNodes SetupCodexNodes(int numberOfNodes)
{
2023-03-21 15:17:48 +01:00
return new OfflineCodexNodes(k8sManager, numberOfNodes);
}
}
2023-03-20 10:37:03 +01:00
public static class GlobalTestFailure
{
public static bool HasFailed { get; set; } = false;
}
}