Restructure solution layout by module
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Text.Json;
|
||||
using StellaOps.Scheduler.Models;
|
||||
|
||||
namespace StellaOps.Scheduler.Models.Tests;
|
||||
|
||||
public sealed class PolicyRunModelsTests
|
||||
{
|
||||
[Fact]
|
||||
public void PolicyRunInputs_NormalizesEnvironmentKeys()
|
||||
{
|
||||
var inputs = new PolicyRunInputs(
|
||||
sbomSet: new[] { "sbom:two", "sbom:one" },
|
||||
env: new[]
|
||||
{
|
||||
new KeyValuePair<string, object?>("Sealed", true),
|
||||
new KeyValuePair<string, object?>("Exposure", "internet"),
|
||||
new KeyValuePair<string, object?>("region", JsonSerializer.SerializeToElement("global"))
|
||||
},
|
||||
captureExplain: true);
|
||||
|
||||
Assert.Equal(new[] { "sbom:one", "sbom:two" }, inputs.SbomSet);
|
||||
Assert.True(inputs.CaptureExplain);
|
||||
Assert.Equal(3, inputs.Environment.Count);
|
||||
Assert.True(inputs.Environment.ContainsKey("sealed"));
|
||||
Assert.Equal(JsonValueKind.True, inputs.Environment["sealed"].ValueKind);
|
||||
Assert.Equal("internet", inputs.Environment["exposure"].GetString());
|
||||
Assert.Equal("global", inputs.Environment["region"].GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PolicyRunStatus_ThrowsOnNegativeAttempts()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new PolicyRunStatus(
|
||||
runId: "run:test",
|
||||
tenantId: "tenant-alpha",
|
||||
policyId: "P-1",
|
||||
policyVersion: 1,
|
||||
mode: PolicyRunMode.Full,
|
||||
status: PolicyRunExecutionStatus.Queued,
|
||||
priority: PolicyRunPriority.Normal,
|
||||
queuedAt: DateTimeOffset.UtcNow,
|
||||
attempts: -1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PolicyDiffSummary_NormalizesSeverityKeys()
|
||||
{
|
||||
var summary = new PolicyDiffSummary(
|
||||
added: 1,
|
||||
removed: 2,
|
||||
unchanged: 3,
|
||||
bySeverity: new[]
|
||||
{
|
||||
new KeyValuePair<string, PolicyDiffSeverityDelta>("critical", new PolicyDiffSeverityDelta(1, 0)),
|
||||
new KeyValuePair<string, PolicyDiffSeverityDelta>("HIGH", new PolicyDiffSeverityDelta(0, 1))
|
||||
});
|
||||
|
||||
Assert.True(summary.BySeverity.ContainsKey("Critical"));
|
||||
Assert.True(summary.BySeverity.ContainsKey("High"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PolicyExplainTrace_LowercasesMetadataKeys()
|
||||
{
|
||||
var trace = new PolicyExplainTrace(
|
||||
findingId: "finding:alpha",
|
||||
policyId: "P-1",
|
||||
policyVersion: 1,
|
||||
tenantId: "tenant-alpha",
|
||||
runId: "run:test",
|
||||
verdict: new PolicyExplainVerdict(PolicyVerdictStatus.Passed, SeverityRank.Low, quiet: false, score: 0, rationale: "ok"),
|
||||
evaluatedAt: DateTimeOffset.UtcNow,
|
||||
metadata: ImmutableSortedDictionary.CreateRange(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("TraceId", "trace-1"),
|
||||
new KeyValuePair<string, string>("ComponentPurl", "pkg:npm/a@1.0.0")
|
||||
}));
|
||||
|
||||
Assert.Equal("trace-1", trace.Metadata["traceid"]);
|
||||
Assert.Equal("pkg:npm/a@1.0.0", trace.Metadata["componentpurl"]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user