up
Some checks failed
api-governance / spectral-lint (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
oas-ci / oas-validate (push) Has been cancelled
SDK Publish & Sign / sdk-publish (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Policy Simulation / policy-simulate (push) Has been cancelled
devportal-offline / build-offline (push) Has been cancelled
Some checks failed
api-governance / spectral-lint (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
oas-ci / oas-validate (push) Has been cancelled
SDK Publish & Sign / sdk-publish (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Policy Simulation / policy-simulate (push) Has been cancelled
devportal-offline / build-offline (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System.Collections.Immutable;
|
||||
using StellaOps.Policy.Engine.Domain;
|
||||
using StellaOps.Policy.Engine.Services;
|
||||
|
||||
namespace StellaOps.Policy.Engine.Tests;
|
||||
|
||||
public sealed class PolicyRuntimeEvaluatorTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task EvaluateAsync_ReturnsDeterministicDecisionAndCaches()
|
||||
{
|
||||
var repo = new InMemoryPolicyPackRepository();
|
||||
await repo.StoreBundleAsync(
|
||||
"pack-1",
|
||||
1,
|
||||
new PolicyBundleRecord(
|
||||
Digest: "sha256:abc",
|
||||
Signature: "sig:sha256:abc",
|
||||
Size: 4,
|
||||
CreatedAt: DateTimeOffset.UnixEpoch,
|
||||
Payload: new byte[] { 1, 2, 3, 4 }.ToImmutableArray()),
|
||||
CancellationToken.None);
|
||||
|
||||
var evaluator = new PolicyRuntimeEvaluator(repo);
|
||||
var request = new PolicyEvaluationRequest("pack-1", 1, "subject-a");
|
||||
|
||||
var first = await evaluator.EvaluateAsync(request, CancellationToken.None);
|
||||
var second = await evaluator.EvaluateAsync(request, CancellationToken.None);
|
||||
|
||||
Assert.Equal(first.Decision, second.Decision);
|
||||
Assert.False(first.Cached);
|
||||
Assert.True(second.Cached);
|
||||
Assert.Equal("pack-1", first.PackId);
|
||||
Assert.Equal(1, first.Version);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EvaluateAsync_ThrowsWhenBundleMissing()
|
||||
{
|
||||
var evaluator = new PolicyRuntimeEvaluator(new InMemoryPolicyPackRepository());
|
||||
var request = new PolicyEvaluationRequest("pack-x", 1, "subject-a");
|
||||
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => evaluator.EvaluateAsync(request, CancellationToken.None));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user