audit notes work completed, test fixes work (95% done), new sprints, new data sources setup and configuration
This commit is contained in:
@@ -0,0 +1,271 @@
|
||||
using StellaOps.Orchestrator.Schemas;
|
||||
using System.Text.Json;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Orchestrator.Schemas.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for OrchestratorEnvelope generic record.
|
||||
/// </summary>
|
||||
public sealed class OrchestratorEnvelopeTests
|
||||
{
|
||||
[Fact]
|
||||
public void OrchestratorEnvelope_RequiredProperties_HaveDefaults()
|
||||
{
|
||||
var envelope = new OrchestratorEnvelope<string>
|
||||
{
|
||||
Payload = "test"
|
||||
};
|
||||
|
||||
Assert.Equal(Guid.Empty, envelope.EventId);
|
||||
Assert.Equal(string.Empty, envelope.Kind);
|
||||
Assert.Equal(0, envelope.Version);
|
||||
Assert.Equal(string.Empty, envelope.Tenant);
|
||||
Assert.Equal(string.Empty, envelope.Source);
|
||||
Assert.Equal(string.Empty, envelope.IdempotencyKey);
|
||||
Assert.Equal("test", envelope.Payload);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OrchestratorEnvelope_WithAllProperties_ContainsValues()
|
||||
{
|
||||
var eventId = Guid.NewGuid();
|
||||
var occurredAt = DateTimeOffset.UtcNow;
|
||||
var recordedAt = occurredAt.AddSeconds(1);
|
||||
|
||||
var envelope = new OrchestratorEnvelope<string>
|
||||
{
|
||||
EventId = eventId,
|
||||
Kind = OrchestratorEventKinds.ScannerReportReady,
|
||||
Version = 1,
|
||||
Tenant = "tenant-001",
|
||||
OccurredAt = occurredAt,
|
||||
RecordedAt = recordedAt,
|
||||
Source = "scanner-service",
|
||||
IdempotencyKey = "idem-key-123",
|
||||
CorrelationId = "corr-456",
|
||||
TraceId = "trace-789",
|
||||
SpanId = "span-abc",
|
||||
Payload = "report-data"
|
||||
};
|
||||
|
||||
Assert.Equal(eventId, envelope.EventId);
|
||||
Assert.Equal(OrchestratorEventKinds.ScannerReportReady, envelope.Kind);
|
||||
Assert.Equal(1, envelope.Version);
|
||||
Assert.Equal("tenant-001", envelope.Tenant);
|
||||
Assert.Equal(occurredAt, envelope.OccurredAt);
|
||||
Assert.Equal(recordedAt, envelope.RecordedAt);
|
||||
Assert.Equal("scanner-service", envelope.Source);
|
||||
Assert.Equal("idem-key-123", envelope.IdempotencyKey);
|
||||
Assert.Equal("corr-456", envelope.CorrelationId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OrchestratorEnvelope_WithScope_ContainsScope()
|
||||
{
|
||||
var scope = new OrchestratorScope
|
||||
{
|
||||
Namespace = "production",
|
||||
Repo = "myapp",
|
||||
Digest = "sha256:abc123",
|
||||
Component = "api",
|
||||
Image = "myapp:v1.0.0"
|
||||
};
|
||||
|
||||
var envelope = new OrchestratorEnvelope<string>
|
||||
{
|
||||
Scope = scope,
|
||||
Payload = "test"
|
||||
};
|
||||
|
||||
Assert.NotNull(envelope.Scope);
|
||||
Assert.Equal("production", envelope.Scope.Namespace);
|
||||
Assert.Equal("myapp", envelope.Scope.Repo);
|
||||
Assert.Equal("sha256:abc123", envelope.Scope.Digest);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OrchestratorEnvelope_WithAttributes_ContainsAttributes()
|
||||
{
|
||||
var attributes = new Dictionary<string, string>
|
||||
{
|
||||
["region"] = "us-east-1",
|
||||
["environment"] = "staging"
|
||||
};
|
||||
|
||||
var envelope = new OrchestratorEnvelope<string>
|
||||
{
|
||||
Attributes = attributes,
|
||||
Payload = "test"
|
||||
};
|
||||
|
||||
Assert.NotNull(envelope.Attributes);
|
||||
Assert.Equal(2, envelope.Attributes.Count);
|
||||
Assert.Equal("us-east-1", envelope.Attributes["region"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OrchestratorEnvelope_OptionalProperties_AreNullByDefault()
|
||||
{
|
||||
var envelope = new OrchestratorEnvelope<string>
|
||||
{
|
||||
Payload = "test"
|
||||
};
|
||||
|
||||
Assert.Null(envelope.RecordedAt);
|
||||
Assert.Null(envelope.CorrelationId);
|
||||
Assert.Null(envelope.TraceId);
|
||||
Assert.Null(envelope.SpanId);
|
||||
Assert.Null(envelope.Scope);
|
||||
Assert.Null(envelope.Attributes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OrchestratorEnvelope_GenericPayload_WorksWithComplexTypes()
|
||||
{
|
||||
var payload = new ScannerReportReadyPayload
|
||||
{
|
||||
ReportId = "report-001",
|
||||
Verdict = "PASS"
|
||||
};
|
||||
|
||||
var envelope = new OrchestratorEnvelope<ScannerReportReadyPayload>
|
||||
{
|
||||
Kind = OrchestratorEventKinds.ScannerReportReady,
|
||||
Payload = payload
|
||||
};
|
||||
|
||||
Assert.Equal("report-001", envelope.Payload.ReportId);
|
||||
Assert.Equal("PASS", envelope.Payload.Verdict);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for OrchestratorScope record.
|
||||
/// </summary>
|
||||
public sealed class OrchestratorScopeTests
|
||||
{
|
||||
[Fact]
|
||||
public void OrchestratorScope_RequiredProperties_HaveDefaults()
|
||||
{
|
||||
var scope = new OrchestratorScope();
|
||||
|
||||
Assert.Null(scope.Namespace);
|
||||
Assert.Equal(string.Empty, scope.Repo);
|
||||
Assert.Equal(string.Empty, scope.Digest);
|
||||
Assert.Null(scope.Component);
|
||||
Assert.Null(scope.Image);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OrchestratorScope_WithAllProperties_ContainsValues()
|
||||
{
|
||||
var scope = new OrchestratorScope
|
||||
{
|
||||
Namespace = "default",
|
||||
Repo = "registry.example.com/myapp",
|
||||
Digest = "sha256:1234567890abcdef",
|
||||
Component = "backend",
|
||||
Image = "myapp:latest"
|
||||
};
|
||||
|
||||
Assert.Equal("default", scope.Namespace);
|
||||
Assert.Equal("registry.example.com/myapp", scope.Repo);
|
||||
Assert.Equal("sha256:1234567890abcdef", scope.Digest);
|
||||
Assert.Equal("backend", scope.Component);
|
||||
Assert.Equal("myapp:latest", scope.Image);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OrchestratorScope_RecordEquality_WorksCorrectly()
|
||||
{
|
||||
var scope1 = new OrchestratorScope
|
||||
{
|
||||
Repo = "myapp",
|
||||
Digest = "sha256:abc"
|
||||
};
|
||||
|
||||
var scope2 = new OrchestratorScope
|
||||
{
|
||||
Repo = "myapp",
|
||||
Digest = "sha256:abc"
|
||||
};
|
||||
|
||||
Assert.Equal(scope1, scope2);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for OrchestratorEventKinds constants.
|
||||
/// </summary>
|
||||
public sealed class OrchestratorEventKindsTests
|
||||
{
|
||||
[Fact]
|
||||
public void OrchestratorEventKinds_ScannerReportReady_HasCorrectValue()
|
||||
{
|
||||
Assert.Equal("scanner.event.report.ready", OrchestratorEventKinds.ScannerReportReady);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OrchestratorEventKinds_ScannerScanCompleted_HasCorrectValue()
|
||||
{
|
||||
Assert.Equal("scanner.event.scan.completed", OrchestratorEventKinds.ScannerScanCompleted);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for ScannerReportReadyPayload record.
|
||||
/// </summary>
|
||||
public sealed class ScannerReportReadyPayloadTests
|
||||
{
|
||||
[Fact]
|
||||
public void ScannerReportReadyPayload_RequiredProperties_HaveDefaults()
|
||||
{
|
||||
var payload = new ScannerReportReadyPayload();
|
||||
|
||||
Assert.Equal(string.Empty, payload.ReportId);
|
||||
Assert.Null(payload.ScanId);
|
||||
Assert.Null(payload.ImageDigest);
|
||||
Assert.Equal(string.Empty, payload.Verdict);
|
||||
Assert.NotNull(payload.Summary);
|
||||
Assert.NotNull(payload.Links);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScannerReportReadyPayload_WithAllProperties_ContainsValues()
|
||||
{
|
||||
var generatedAt = DateTimeOffset.UtcNow;
|
||||
|
||||
var payload = new ScannerReportReadyPayload
|
||||
{
|
||||
ReportId = "rpt-001",
|
||||
ScanId = "scan-001",
|
||||
ImageDigest = "sha256:xyz789",
|
||||
GeneratedAt = generatedAt,
|
||||
Verdict = "FAIL",
|
||||
QuietedFindingCount = 5
|
||||
};
|
||||
|
||||
Assert.Equal("rpt-001", payload.ReportId);
|
||||
Assert.Equal("scan-001", payload.ScanId);
|
||||
Assert.Equal("sha256:xyz789", payload.ImageDigest);
|
||||
Assert.Equal(generatedAt, payload.GeneratedAt);
|
||||
Assert.Equal("FAIL", payload.Verdict);
|
||||
Assert.Equal(5, payload.QuietedFindingCount);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("PASS")]
|
||||
[InlineData("FAIL")]
|
||||
[InlineData("WARN")]
|
||||
[InlineData("UNKNOWN")]
|
||||
public void ScannerReportReadyPayload_Verdict_SupportedValues(string verdict)
|
||||
{
|
||||
var payload = new ScannerReportReadyPayload
|
||||
{
|
||||
Verdict = verdict
|
||||
};
|
||||
|
||||
Assert.Equal(verdict, payload.Verdict);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<IsPackable>false</IsPackable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<UseXunitV3>true</UseXunitV3>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Moq" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\StellaOps.Orchestrator.Schemas\StellaOps.Orchestrator.Schemas.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
|
||||
"diagnosticMessages": true,
|
||||
"parallelizeAssembly": true,
|
||||
"parallelizeTestCollections": true,
|
||||
"maxParallelThreads": -1
|
||||
}
|
||||
Reference in New Issue
Block a user