Files
git.stella-ops.org/src/__Tests/interop/StellaOps.Interop.Tests/ToolManagerTests.RunAsync.cs
2026-02-04 19:59:20 +02:00

63 lines
1.7 KiB
C#

using FluentAssertions;
using StellaOps.Interop;
using Xunit;
using Xunit.Sdk;
namespace StellaOps.Interop.Tests;
public sealed partial class ToolManagerTests
{
[Fact]
public async Task RunAsync_ReturnsFailure_WhenToolMissingAsync()
{
var workDir = CreateTempDirectory();
try
{
var manager = new ToolManager(workDir);
var result = await manager.RunAsync("missing-tool", "--version", CancellationToken.None);
result.Success.Should().BeFalse();
result.Error.Should().Contain("Tool not found");
result.ExitCode.Should().Be(-1);
}
finally
{
DeleteDirectory(workDir);
}
}
[Fact]
public async Task RunAsync_ReturnsSuccess_WhenShellExecutesScriptAsync()
{
var workDir = CreateTempDirectory();
try
{
var scriptPath = WriteShellScript(workDir);
var shellPath = ResolveShellPath();
if (string.IsNullOrWhiteSpace(shellPath) || !File.Exists(shellPath))
throw SkipException.ForSkip("Shell not available for interop tool test.");
var toolPaths = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
["shell"] = shellPath
};
var args = OperatingSystem.IsWindows()
? $"/c \"{scriptPath}\""
: $"\"{scriptPath}\"";
var manager = new ToolManager(workDir, toolPaths);
var result = await manager.RunAsync("shell", args, CancellationToken.None);
result.Success.Should().BeTrue();
result.StdOut.Should().Contain("ok");
}
finally
{
DeleteDirectory(workDir);
}
}
}