mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-03 03:54:24 +00:00
76 lines
3.1 KiB
C#
76 lines
3.1 KiB
C#
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;
|
||
|
|
}
|
||
|
|
}
|