mirror of
https://github.com/Radarr/Radarr.git
synced 2025-04-24 06:27:08 -04:00
Cache integration test DB to avoid repeated migrations
This commit is contained in:
parent
f3308827d0
commit
456169b8d2
2 changed files with 57 additions and 4 deletions
20
src/NzbDrone.Integration.Test/IntegrationTestCleanup.cs
Normal file
20
src/NzbDrone.Integration.Test/IntegrationTestCleanup.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace NzbDrone.Integration.Test
|
||||
{
|
||||
[SetUpFixture]
|
||||
public class IntegrationTestSetup
|
||||
{
|
||||
[OneTimeSetUp]
|
||||
[OneTimeTearDown]
|
||||
public void CleanUp()
|
||||
{
|
||||
var dir = Path.Combine(TestContext.CurrentContext.TestDirectory, "CachedAppData");
|
||||
if (Directory.Exists(dir))
|
||||
{
|
||||
Directory.Delete(dir, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,13 +27,43 @@ namespace NzbDrone.Test.Common
|
|||
_restClient = new RestClient("http://localhost:7878/api/v3");
|
||||
}
|
||||
|
||||
private void CopyDirectory(string source, string target)
|
||||
{
|
||||
foreach (var dirPath in Directory.GetDirectories(source, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
Directory.CreateDirectory(dirPath.Replace(source, target));
|
||||
}
|
||||
|
||||
foreach (var newPath in Directory.GetFiles(source, "*.*", SearchOption.AllDirectories))
|
||||
{
|
||||
File.Copy(newPath, newPath.Replace(source, target), true);
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
AppData = Path.Combine(TestContext.CurrentContext.TestDirectory, "_intg_" + TestBase.GetUID());
|
||||
Directory.CreateDirectory(AppData);
|
||||
|
||||
GenerateConfigFile();
|
||||
if (!Directory.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, "CachedAppData")))
|
||||
{
|
||||
Directory.CreateDirectory(AppData);
|
||||
GenerateConfigFile();
|
||||
StartInternal();
|
||||
KillAll(false);
|
||||
|
||||
CopyDirectory(AppData, Path.Combine(TestContext.CurrentContext.TestDirectory, "CachedAppData"));
|
||||
}
|
||||
else
|
||||
{
|
||||
CopyDirectory(Path.Combine(TestContext.CurrentContext.TestDirectory, "CachedAppData"), AppData);
|
||||
GenerateConfigFile();
|
||||
}
|
||||
|
||||
StartInternal();
|
||||
}
|
||||
|
||||
private void StartInternal()
|
||||
{
|
||||
string consoleExe;
|
||||
if (OsInfo.IsWindows)
|
||||
{
|
||||
|
@ -85,7 +115,7 @@ namespace NzbDrone.Test.Common
|
|||
}
|
||||
}
|
||||
|
||||
public void KillAll()
|
||||
public void KillAll(bool delete = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -102,7 +132,10 @@ namespace NzbDrone.Test.Common
|
|||
// May happen if the process closes while being closed
|
||||
}
|
||||
|
||||
TestBase.DeleteTempFolder(AppData);
|
||||
if (delete)
|
||||
{
|
||||
TestBase.DeleteTempFolder(AppData);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start(string outputRadarrConsoleExe)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue