mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-04 04:52:01 +00:00
Moved temporary files into a folder of their own below the data directory (#1245)
This commit is contained in:
1 parent
ddfc632b63
commit
12d3e1ec6c
52 files changed
+1219
-396
No files matched your search
@@ -0,0 +1,76 @@
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
|
||||
namespace AIStudio.Tests.Tools.PluginSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Checks how a deployment which AI Studio downloaded from the configuration server of an organization reaches its place.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// AI Studio unpacks the deployment in its temporary folder and moves it to plugins/.config afterward. That folder
|
||||
/// is missing on a new installation until the first deployment arrives, and once somebody deleted it.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class ConfigPluginDeploymentTests
|
||||
{
|
||||
private string dataDirectory = string.Empty;
|
||||
|
||||
[SetUp]
|
||||
public void CreateDataDirectory()
|
||||
{
|
||||
// A user name beyond ASCII, as in the path of many data directories:
|
||||
this.dataDirectory = Path.Combine(Path.GetTempPath(), $"ai-studio-deployment-ä-ж-日本-{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(Path.Combine(this.dataDirectory, "plugins"));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void DeleteDataDirectory()
|
||||
{
|
||||
if (Directory.Exists(this.dataDirectory))
|
||||
Directory.Delete(this.dataDirectory, true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheFirstDeploymentArrivesAlthoughItsFolderIsMissing()
|
||||
{
|
||||
var stagedDirectory = this.StageDeployment("ID = \"first\"");
|
||||
var deploymentDirectory = Path.Combine(this.dataDirectory, "plugins", ".config", Guid.NewGuid().ToString());
|
||||
|
||||
PluginFactory.MoveDeploymentIntoPlace(stagedDirectory, deploymentDirectory);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(File.ReadAllText(Path.Combine(deploymentDirectory, "plugin.lua")), Is.EqualTo("ID = \"first\""));
|
||||
Assert.That(Directory.Exists(stagedDirectory), Is.False);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ADeploymentArrivesNextToTheOthers()
|
||||
{
|
||||
var otherDeploymentDirectory = Path.Combine(this.dataDirectory, "plugins", ".config", Guid.NewGuid().ToString());
|
||||
Directory.CreateDirectory(otherDeploymentDirectory);
|
||||
File.WriteAllText(Path.Combine(otherDeploymentDirectory, "plugin.lua"), "ID = \"other\"");
|
||||
|
||||
var stagedDirectory = this.StageDeployment("ID = \"next\"");
|
||||
var deploymentDirectory = Path.Combine(this.dataDirectory, "plugins", ".config", Guid.NewGuid().ToString());
|
||||
|
||||
PluginFactory.MoveDeploymentIntoPlace(stagedDirectory, deploymentDirectory);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(File.ReadAllText(Path.Combine(deploymentDirectory, "plugin.lua")), Is.EqualTo("ID = \"next\""));
|
||||
Assert.That(File.ReadAllText(Path.Combine(otherDeploymentDirectory, "plugin.lua")), Is.EqualTo("ID = \"other\""));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Places an unpacked deployment in the temporary folder below the data directory, as the download does.
|
||||
/// </summary>
|
||||
private string StageDeployment(string pluginCode)
|
||||
{
|
||||
var stagedDirectory = Path.Combine(this.dataDirectory, "tmp", Guid.NewGuid().ToString("N"), "deployment");
|
||||
Directory.CreateDirectory(stagedDirectory);
|
||||
File.WriteAllText(Path.Combine(stagedDirectory, "plugin.lua"), pluginCode);
|
||||
return stagedDirectory;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user