Add unit tests for SBOM ingestion and transformation
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
- Implement `SbomIngestServiceCollectionExtensionsTests` to verify the SBOM ingestion pipeline exports snapshots correctly. - Create `SbomIngestTransformerTests` to ensure the transformation produces expected nodes and edges, including deduplication of license nodes and normalization of timestamps. - Add `SbomSnapshotExporterTests` to test the export functionality for manifest, adjacency, nodes, and edges. - Introduce `VexOverlayTransformerTests` to validate the transformation of VEX nodes and edges. - Set up project file for the test project with necessary dependencies and configurations. - Include JSON fixture files for testing purposes.
This commit is contained in:
@@ -26,8 +26,70 @@ public sealed class PolicyRunModelsTests
|
||||
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 PolicySimulationWebhookPayloadFactory_ComputesSucceeded()
|
||||
{
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var job = CreateJob(PolicyRunJobStatus.Completed, now);
|
||||
var status = PolicyRunStatusFactory.Create(job, now);
|
||||
|
||||
var payload = PolicySimulationWebhookPayloadFactory.Create(status, now);
|
||||
|
||||
Assert.Equal(succeeded, payload.Result);
|
||||
Assert.Equal(status, payload.Simulation);
|
||||
Assert.Null(payload.Reason);
|
||||
Assert.NotNull(payload.LatencySeconds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PolicySimulationWebhookPayloadFactory_ComputesFailureReason()
|
||||
{
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var job = CreateJob(PolicyRunJobStatus.Failed, now) with { LastError = timeout };
|
||||
var status = PolicyRunStatusFactory.Create(job, now);
|
||||
|
||||
var payload = PolicySimulationWebhookPayloadFactory.Create(status, now);
|
||||
|
||||
Assert.Equal(failed, payload.Result);
|
||||
Assert.Equal(timeout, payload.Reason);
|
||||
}
|
||||
|
||||
private static PolicyRunJob CreateJob(PolicyRunJobStatus status, DateTimeOffset timestamp)
|
||||
{
|
||||
return new PolicyRunJob(
|
||||
SchemaVersion: SchedulerSchemaVersions.PolicyRunJob,
|
||||
Id: job,
|
||||
TenantId: tenant,
|
||||
PolicyId: policy,
|
||||
PolicyVersion: 1,
|
||||
Mode: PolicyRunMode.Simulate,
|
||||
Priority: PolicyRunPriority.Normal,
|
||||
PriorityRank: 0,
|
||||
RunId: run,
|
||||
RequestedBy: tester,
|
||||
CorrelationId: corr,
|
||||
Metadata: null,
|
||||
Inputs: PolicyRunInputs.Empty,
|
||||
QueuedAt: timestamp,
|
||||
Status: status,
|
||||
AttemptCount: 1,
|
||||
LastAttemptAt: timestamp,
|
||||
LastError: status == PolicyRunJobStatus.Failed ? error : null,
|
||||
CreatedAt: timestamp,
|
||||
UpdatedAt: timestamp,
|
||||
AvailableAt: timestamp,
|
||||
SubmittedAt: timestamp,
|
||||
CompletedAt: status == PolicyRunJobStatus.Completed ? timestamp : null,
|
||||
LeaseOwner: null,
|
||||
LeaseExpiresAt: null,
|
||||
CancellationRequested: status == PolicyRunJobStatus.Cancelled,
|
||||
CancellationRequestedAt: null,
|
||||
CancellationReason: null,
|
||||
CancelledAt: status == PolicyRunJobStatus.Cancelled ? timestamp : null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PolicyRunStatus_ThrowsOnNegativeAttempts()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user