tests fixes

This commit is contained in:
master
2026-01-27 08:23:42 +02:00
parent c305d05d32
commit 82caceba56
58 changed files with 651 additions and 312 deletions

View File

@@ -22,7 +22,7 @@ public class ExplainBlockCommandTests
[Theory]
[InlineData("sha256:abc123def456", "sha256:abc123def456")]
[InlineData("SHA256:ABC123DEF456", "sha256:abc123def456")]
[InlineData("abc123def456789012345678901234567890123456789012345678901234", "sha256:abc123def456789012345678901234567890123456789012345678901234")]
[InlineData("abc123def456789012345678901234567890123456789012345678901234abcd", "sha256:abc123def456789012345678901234567890123456789012345678901234abcd")] // SHA-256 is 64 hex chars
[InlineData("registry.example.com/image@sha256:abc123", "sha256:abc123")]
public void NormalizeDigest_ValidFormats_ReturnsNormalized(string input, string expected)
{

View File

@@ -52,10 +52,10 @@ public sealed class GroundTruthCommandTests
}
[Fact]
public void BuildGroundTruthCommand_HasFourSubcommands()
public void BuildGroundTruthCommand_HasSixSubcommands()
{
// Assert
_groundTruthCommand.Subcommands.Should().HaveCount(4);
// Assert - Updated to reflect current command structure
_groundTruthCommand.Subcommands.Should().HaveCount(6);
}
[Fact]
@@ -274,13 +274,13 @@ public sealed class GroundTruthCommandTests
#region Validate Subcommand Tests
[Fact]
public void Validate_HasThreeSubcommands()
public void Validate_HasFourSubcommands()
{
// Act
var validateCommand = _groundTruthCommand.Subcommands.First(c => c.Name == "validate");
// Assert
validateCommand.Subcommands.Should().HaveCount(3);
// Assert - Updated to reflect current command structure
validateCommand.Subcommands.Should().HaveCount(4);
}
[Fact]

View File

@@ -48,17 +48,20 @@ public sealed class SarifExportCommandTests
using var loggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.None));
var services = new ServiceCollection()
.AddSingleton(client.Object)
.AddSingleton<IBackendOperationsClient>(client.Object)
.AddSingleton<ILoggerFactory>(loggerFactory)
.AddSingleton(new VerbosityState())
.BuildServiceProvider();
var writer = new StringWriter();
var errorWriter = new StringWriter();
var originalOut = Console.Out;
var originalError = Console.Error;
try
{
Console.SetOut(writer);
Console.SetError(errorWriter);
await CommandHandlers.HandleScanSarifExportAsync(
services,
"scan-123",
@@ -73,11 +76,19 @@ public sealed class SarifExportCommandTests
finally
{
Console.SetOut(originalOut);
Console.SetError(originalError);
}
// Assert
using var doc = JsonDocument.Parse(writer.ToString());
var properties = doc.RootElement.GetProperty("runs")[0].GetProperty("properties");
var output = writer.ToString();
var errorOutput = errorWriter.ToString();
Assert.True(string.IsNullOrEmpty(errorOutput), $"Unexpected error output: {errorOutput}");
Assert.False(string.IsNullOrEmpty(output), "Expected SARIF output but got empty string");
using var doc = JsonDocument.Parse(output);
Assert.True(doc.RootElement.TryGetProperty("runs", out var runs), $"Output missing 'runs': {output}");
Assert.True(runs.GetArrayLength() > 0, $"'runs' array is empty in output: {output}");
var run0 = runs[0];
Assert.True(run0.TryGetProperty("properties", out var properties), $"run[0] missing 'properties'. run[0] = {run0}");
Assert.Equal("scan-123", properties.GetProperty("digest").GetString());
Assert.True(properties.TryGetProperty("scanTimestamp", out _));
Assert.True(properties.TryGetProperty("policyProfileId", out _));

View File

@@ -175,8 +175,8 @@ public class UnknownsGreyQueueCommandTests
// Act
var json = JsonSerializer.Serialize(proof, new JsonSerializerOptions { WriteIndented = true });
// Assert
Assert.Contains("\"fingerprintId\"", json.ToLowerInvariant());
// Assert - After ToLowerInvariant(), all text including property names are lowercase
Assert.Contains("\"fingerprintid\"", json.ToLowerInvariant());
Assert.Contains("\"triggers\"", json.ToLowerInvariant());
Assert.Contains("\"evidencerefs\"", json.ToLowerInvariant());
Assert.Contains("\"observationstate\"", json.ToLowerInvariant());