nuget reorganization
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StellaOps.Signals.Models;
|
||||
using StellaOps.Signals.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Signals.Tests;
|
||||
|
||||
public class InMemoryEventsPublisherTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task PublishFactUpdatedAsync_EmitsStructuredEvent()
|
||||
{
|
||||
var logger = new TestLogger<InMemoryEventsPublisher>();
|
||||
var publisher = new InMemoryEventsPublisher(logger);
|
||||
|
||||
var fact = new ReachabilityFactDocument
|
||||
{
|
||||
SubjectKey = "tenant:image@sha256:abc",
|
||||
CallgraphId = "cg-123",
|
||||
ComputedAt = System.DateTimeOffset.Parse("2025-11-18T12:00:00Z"),
|
||||
States = new List<ReachabilityStateDocument>
|
||||
{
|
||||
new() { Target = "pkg:pypi/django", Reachable = true, Confidence = 0.9 },
|
||||
new() { Target = "pkg:pypi/requests", Reachable = false, Confidence = 0.2 }
|
||||
},
|
||||
RuntimeFacts = new List<RuntimeFactDocument>
|
||||
{
|
||||
new() { SymbolId = "funcA", HitCount = 3 }
|
||||
}
|
||||
};
|
||||
|
||||
await publisher.PublishFactUpdatedAsync(fact, CancellationToken.None);
|
||||
|
||||
Assert.Contains("signals.fact.updated", logger.LastMessage);
|
||||
Assert.Contains("\"subjectKey\":\"tenant:image@sha256:abc\"", logger.LastMessage);
|
||||
Assert.Contains("\"callgraphId\":\"cg-123\"", logger.LastMessage);
|
||||
Assert.Contains("\"reachableCount\":1", logger.LastMessage);
|
||||
Assert.Contains("\"unreachableCount\":1", logger.LastMessage);
|
||||
Assert.Contains("\"runtimeFactsCount\":1", logger.LastMessage);
|
||||
}
|
||||
|
||||
private sealed class TestLogger<T> : ILogger<T>
|
||||
{
|
||||
public string LastMessage { get; private set; } = string.Empty;
|
||||
|
||||
public IDisposable BeginScope<TState>(TState state) => NullScope.Instance;
|
||||
|
||||
public bool IsEnabled(LogLevel logLevel) => true;
|
||||
|
||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, System.Exception? exception, Func<TState, System.Exception?, string> formatter)
|
||||
{
|
||||
LastMessage = formatter(state, exception);
|
||||
}
|
||||
|
||||
private sealed class NullScope : IDisposable
|
||||
{
|
||||
public static readonly NullScope Instance = new();
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user