audit remarks work
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -54,8 +55,20 @@ public sealed class ScannerDownloadVerifyTests
|
||||
internal static class CommandHandlersTestShim
|
||||
{
|
||||
public static Task VerifyBundlePublicAsync(string path, ILogger logger, CancellationToken token)
|
||||
=> typeof(CommandHandlers)
|
||||
.GetMethod("VerifyBundleAsync", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)!
|
||||
.Invoke(null, new object[] { path, logger, token }) as Task
|
||||
?? Task.CompletedTask;
|
||||
{
|
||||
var method = typeof(CommandHandlers).GetMethod(
|
||||
"VerifyBundleAsync",
|
||||
BindingFlags.NonPublic | BindingFlags.Static,
|
||||
binder: null,
|
||||
types: new[] { typeof(string), typeof(ILogger), typeof(CancellationToken) },
|
||||
modifiers: null);
|
||||
|
||||
if (method is null)
|
||||
{
|
||||
throw new MissingMethodException(nameof(CommandHandlers), "VerifyBundleAsync");
|
||||
}
|
||||
|
||||
return method.Invoke(null, new object[] { path, logger, token }) as Task
|
||||
?? Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.CommandLine;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StellaOps.Cli.Commands;
|
||||
using StellaOps.Cli.Configuration;
|
||||
|
||||
namespace StellaOps.Cli.Tests.Commands;
|
||||
|
||||
public sealed class ToolsCommandGroupTests
|
||||
{
|
||||
[Fact]
|
||||
public void Create_ExposesToolsCommands()
|
||||
{
|
||||
using var loggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.None));
|
||||
var services = new ServiceCollection().BuildServiceProvider();
|
||||
var root = CommandFactory.Create(services, new StellaOpsCliOptions(), CancellationToken.None, loggerFactory);
|
||||
|
||||
var tools = Assert.Single(root.Subcommands, command => string.Equals(command.Name, "tools", StringComparison.Ordinal));
|
||||
|
||||
Assert.Contains(tools.Subcommands, command => string.Equals(command.Name, "policy-dsl-validate", StringComparison.Ordinal));
|
||||
Assert.Contains(tools.Subcommands, command => string.Equals(command.Name, "policy-schema-export", StringComparison.Ordinal));
|
||||
Assert.Contains(tools.Subcommands, command => string.Equals(command.Name, "policy-simulation-smoke", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToolsCommand_PolicyDslValidator_HasExpectedOptions()
|
||||
{
|
||||
var command = BuildToolsCommand().Subcommands.First(c => c.Name == "policy-dsl-validate");
|
||||
|
||||
Assert.NotNull(FindOption(command, "--strict", "-s"));
|
||||
Assert.NotNull(FindOption(command, "--json", "-j"));
|
||||
Assert.Contains(command.Arguments, argument => string.Equals(argument.Name, "inputs", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToolsCommand_PolicySchemaExporter_HasExpectedOptions()
|
||||
{
|
||||
var command = BuildToolsCommand().Subcommands.First(c => c.Name == "policy-schema-export");
|
||||
|
||||
Assert.NotNull(FindOption(command, "--output", "-o"));
|
||||
Assert.NotNull(FindOption(command, "--repo-root", "-r"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToolsCommand_PolicySimulationSmoke_HasExpectedOptions()
|
||||
{
|
||||
var command = BuildToolsCommand().Subcommands.First(c => c.Name == "policy-simulation-smoke");
|
||||
|
||||
Assert.NotNull(FindOption(command, "--scenario-root", "-r"));
|
||||
Assert.NotNull(FindOption(command, "--output", "-o"));
|
||||
Assert.NotNull(FindOption(command, "--repo-root"));
|
||||
Assert.NotNull(FindOption(command, "--fixed-time"));
|
||||
}
|
||||
|
||||
private static Command BuildToolsCommand()
|
||||
{
|
||||
using var loggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.None));
|
||||
return ToolsCommandGroup.BuildToolsCommand(loggerFactory, CancellationToken.None);
|
||||
}
|
||||
|
||||
private static Option? FindOption(Command command, params string[] aliases)
|
||||
{
|
||||
return command.Options.FirstOrDefault(option =>
|
||||
aliases.Any(alias => string.Equals(option.Name, alias, StringComparison.Ordinal) || option.Aliases.Contains(alias)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user