stabilizaiton work - projects rework for maintenanceability and ui livening

This commit is contained in:
master
2026-02-03 23:40:04 +02:00
parent 074ce117ba
commit 557feefdc3
3305 changed files with 186813 additions and 107843 deletions

View File

@@ -0,0 +1,79 @@
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using FluentAssertions;
using StellaOps.TestKit.Observability;
using Xunit;
namespace StellaOps.TestKit.Tests;
public sealed partial class ObservabilityContractTests
{
[Fact]
public void MetricExists_Present_NoException()
{
using var meter = new Meter("TestMeter1");
using var capture = new MetricsCapture("TestMeter1");
var counter = meter.CreateCounter<long>("test_requests_total");
counter.Add(1);
var act = () => MetricsContractAssert.MetricExists(capture, "test_requests_total");
act.Should().NotThrow();
}
[Fact]
public void MetricExists_Missing_ThrowsContractViolation()
{
using var meter = new Meter("TestMeter2");
using var capture = new MetricsCapture("TestMeter2");
var counter = meter.CreateCounter<long>("some_other_metric");
counter.Add(1);
var act = () => MetricsContractAssert.MetricExists(capture, "missing_metric");
act.Should().Throw<ContractViolationException>()
.WithMessage("*missing_metric*not found*");
}
[Fact]
public void LabelCardinalityBounded_WithinThreshold_NoException()
{
using var meter = new Meter("TestMeter3");
using var capture = new MetricsCapture("TestMeter3");
var counter = meter.CreateCounter<long>("http_requests_total");
counter.Add(1, new KeyValuePair<string, object?>("method", "GET"));
counter.Add(1, new KeyValuePair<string, object?>("method", "POST"));
var act = () => MetricsContractAssert.LabelCardinalityBounded(
capture,
"http_requests_total",
maxLabels: 10);
act.Should().NotThrow();
}
[Fact]
public void LabelCardinalityBounded_ExceedsThreshold_ThrowsContractViolation()
{
using var meter = new Meter("TestMeter4");
using var capture = new MetricsCapture("TestMeter4");
var counter = meter.CreateCounter<long>("requests_by_user");
for (int i = 0; i < 10; i++)
{
counter.Add(1, new KeyValuePair<string, object?>("user_id", $"user-{i}"));
}
var act = () => MetricsContractAssert.LabelCardinalityBounded(
capture,
"requests_by_user",
maxLabels: 5);
act.Should().Throw<ContractViolationException>()
.WithMessage("*cardinality*exceeds*");
}
}