This commit is contained in:
master
2026-02-04 19:59:20 +02:00
parent 557feefdc3
commit 5548cf83bf
1479 changed files with 53557 additions and 40339 deletions

View File

@@ -2,11 +2,9 @@ using System.Text;
using FluentAssertions;
using StellaOps.Interop;
using Xunit;
using Xunit.Sdk;
namespace StellaOps.Interop.Tests;
public sealed class ToolManagerTests
public sealed partial class ToolManagerTests
{
[Fact]
public void ResolveToolPath_UsesConfiguredPath()
@@ -73,86 +71,4 @@ public sealed class ToolManagerTests
}
}
[Fact]
public async Task RunAsync_ReturnsFailure_WhenToolMissing()
{
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_WhenShellExecutesScript()
{
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);
}
}
private static string ResolveShellPath()
=> OperatingSystem.IsWindows()
? Environment.GetEnvironmentVariable("ComSpec") ?? string.Empty
: "/bin/sh";
private static string WriteShellScript(string directory)
{
var scriptName = OperatingSystem.IsWindows() ? "interop-tool.cmd" : "interop-tool.sh";
var scriptPath = Path.Combine(directory, scriptName);
var content = OperatingSystem.IsWindows()
? "@echo off\r\necho ok\r\nexit /b 0\r\n"
: "#!/bin/sh\n\necho ok\nexit 0\n";
File.WriteAllText(scriptPath, content, Encoding.ASCII);
return scriptPath;
}
private static string CreateTempDirectory()
{
var path = Path.Combine(Path.GetTempPath(), $"interop-tool-{Guid.NewGuid():N}");
Directory.CreateDirectory(path);
return path;
}
private static void DeleteDirectory(string path)
{
if (Directory.Exists(path))
Directory.Delete(path, recursive: true);
}
}