75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using System.Text;
|
|
using FluentAssertions;
|
|
using StellaOps.Interop;
|
|
using Xunit;
|
|
namespace StellaOps.Interop.Tests;
|
|
|
|
public sealed partial class ToolManagerTests
|
|
{
|
|
[Fact]
|
|
public void ResolveToolPath_UsesConfiguredPath()
|
|
{
|
|
var workDir = CreateTempDirectory();
|
|
try
|
|
{
|
|
var toolPath = Path.Combine(workDir, OperatingSystem.IsWindows() ? "stub-tool.exe" : "stub-tool");
|
|
File.WriteAllText(toolPath, "stub", Encoding.ASCII);
|
|
|
|
var toolPaths = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["stub-tool"] = toolPath
|
|
};
|
|
|
|
var manager = new ToolManager(workDir, toolPaths);
|
|
|
|
manager.ResolveToolPath("stub-tool").Should().Be(toolPath);
|
|
}
|
|
finally
|
|
{
|
|
DeleteDirectory(workDir);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ResolveToolPath_UsesPathProbe()
|
|
{
|
|
var workDir = CreateTempDirectory();
|
|
var toolDir = CreateTempDirectory();
|
|
var originalPath = Environment.GetEnvironmentVariable("PATH");
|
|
try
|
|
{
|
|
var toolFile = OperatingSystem.IsWindows() ? "probe-tool.exe" : "probe-tool";
|
|
var toolPath = Path.Combine(toolDir, toolFile);
|
|
File.WriteAllText(toolPath, "stub", Encoding.ASCII);
|
|
|
|
Environment.SetEnvironmentVariable("PATH", toolDir);
|
|
|
|
var manager = new ToolManager(workDir);
|
|
manager.ResolveToolPath("probe-tool").Should().Be(toolPath);
|
|
}
|
|
finally
|
|
{
|
|
Environment.SetEnvironmentVariable("PATH", originalPath);
|
|
DeleteDirectory(toolDir);
|
|
DeleteDirectory(workDir);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void FindOnPath_ReturnsNull_WhenPathMissing()
|
|
{
|
|
var originalPath = Environment.GetEnvironmentVariable("PATH");
|
|
try
|
|
{
|
|
Environment.SetEnvironmentVariable("PATH", string.Empty);
|
|
|
|
ToolManager.FindOnPath("missing-tool").Should().BeNull();
|
|
}
|
|
finally
|
|
{
|
|
Environment.SetEnvironmentVariable("PATH", originalPath);
|
|
}
|
|
}
|
|
|
|
}
|