audit work, doctors work

This commit is contained in:
master
2026-01-12 23:39:07 +02:00
parent 9330c64349
commit b8868a5f13
80 changed files with 12659 additions and 87 deletions

View File

@@ -0,0 +1,168 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using StellaOps.Doctor.Models;
using StellaOps.Doctor.Plugins;
using StellaOps.Doctor.Plugins.ServiceGraph;
using Xunit;
namespace StellaOps.Doctor.Plugins.ServiceGraph.Tests;
[Trait("Category", "Unit")]
public class ServiceGraphPluginTests
{
[Fact]
public void PluginId_ReturnsExpectedValue()
{
var plugin = new ServiceGraphPlugin();
Assert.Equal("stellaops.doctor.servicegraph", plugin.PluginId);
}
[Fact]
public void DisplayName_ReturnsExpectedValue()
{
var plugin = new ServiceGraphPlugin();
Assert.Equal("Service Graph", plugin.DisplayName);
}
[Fact]
public void Category_ReturnsServiceGraph()
{
var plugin = new ServiceGraphPlugin();
Assert.Equal(DoctorCategory.ServiceGraph, plugin.Category);
}
[Fact]
public void Version_ReturnsValidVersion()
{
var plugin = new ServiceGraphPlugin();
Assert.NotNull(plugin.Version);
Assert.True(plugin.Version >= new Version(1, 0, 0));
}
[Fact]
public void MinEngineVersion_ReturnsValidVersion()
{
var plugin = new ServiceGraphPlugin();
Assert.NotNull(plugin.MinEngineVersion);
Assert.True(plugin.MinEngineVersion >= new Version(1, 0, 0));
}
[Fact]
public void IsAvailable_ReturnsTrue()
{
var plugin = new ServiceGraphPlugin();
var services = new ServiceCollection().BuildServiceProvider();
Assert.True(plugin.IsAvailable(services));
}
[Fact]
public void GetChecks_ReturnsSixChecks()
{
var plugin = new ServiceGraphPlugin();
var context = CreateTestContext();
var checks = plugin.GetChecks(context);
Assert.Equal(6, checks.Count);
}
[Fact]
public void GetChecks_ContainsBackendConnectivityCheck()
{
var plugin = new ServiceGraphPlugin();
var context = CreateTestContext();
var checks = plugin.GetChecks(context);
Assert.Contains(checks, c => c.CheckId == "check.servicegraph.backend");
}
[Fact]
public void GetChecks_ContainsValkeyConnectivityCheck()
{
var plugin = new ServiceGraphPlugin();
var context = CreateTestContext();
var checks = plugin.GetChecks(context);
Assert.Contains(checks, c => c.CheckId == "check.servicegraph.valkey");
}
[Fact]
public void GetChecks_ContainsMessageQueueCheck()
{
var plugin = new ServiceGraphPlugin();
var context = CreateTestContext();
var checks = plugin.GetChecks(context);
Assert.Contains(checks, c => c.CheckId == "check.servicegraph.mq");
}
[Fact]
public void GetChecks_ContainsServiceEndpointsCheck()
{
var plugin = new ServiceGraphPlugin();
var context = CreateTestContext();
var checks = plugin.GetChecks(context);
Assert.Contains(checks, c => c.CheckId == "check.servicegraph.endpoints");
}
[Fact]
public void GetChecks_ContainsCircuitBreakerStatusCheck()
{
var plugin = new ServiceGraphPlugin();
var context = CreateTestContext();
var checks = plugin.GetChecks(context);
Assert.Contains(checks, c => c.CheckId == "check.servicegraph.circuitbreaker");
}
[Fact]
public void GetChecks_ContainsServiceTimeoutCheck()
{
var plugin = new ServiceGraphPlugin();
var context = CreateTestContext();
var checks = plugin.GetChecks(context);
Assert.Contains(checks, c => c.CheckId == "check.servicegraph.timeouts");
}
[Fact]
public async Task InitializeAsync_CompletesSuccessfully()
{
var plugin = new ServiceGraphPlugin();
var context = CreateTestContext();
await plugin.InitializeAsync(context, CancellationToken.None);
// Should complete without throwing
}
private static DoctorPluginContext CreateTestContext(IConfiguration? configuration = null)
{
var services = new ServiceCollection().BuildServiceProvider();
configuration ??= new ConfigurationBuilder().Build();
return new DoctorPluginContext
{
Services = services,
Configuration = configuration,
TimeProvider = TimeProvider.System,
Logger = NullLogger.Instance,
EnvironmentName = "Test",
PluginConfig = configuration.GetSection("Doctor:Plugins:ServiceGraph")
};
}
}