doctor: complete runtime check documentation sprint

Signed-off-by: master <>
This commit is contained in:
master
2026-03-31 23:26:24 +03:00
parent 404d50bcb7
commit 152c1b1357
54 changed files with 2210 additions and 258 deletions

View File

@@ -0,0 +1,71 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging.Abstractions;
using StellaOps.Doctor.Models;
using StellaOps.Doctor.Plugins;
using StellaOps.Doctor.Plugins.Database.Checks;
using Xunit;
namespace StellaOps.Doctor.Plugins.Database.Tests;
[Trait("Category", "Unit")]
public sealed class DatabaseCheckRunbookTests
{
[Theory]
[InlineData("connection", "docs/doctor/articles/postgres/db-connection.md")]
[InlineData("pending", "docs/doctor/articles/postgres/db-migrations-pending.md")]
[InlineData("failed", "docs/doctor/articles/postgres/db-migrations-failed.md")]
[InlineData("schema", "docs/doctor/articles/postgres/db-schema-version.md")]
[InlineData("pool-health", "docs/doctor/articles/postgres/db-pool-health.md")]
[InlineData("pool-size", "docs/doctor/articles/postgres/db-pool-size.md")]
[InlineData("latency", "docs/doctor/articles/postgres/db-latency.md")]
[InlineData("permissions", "docs/doctor/articles/postgres/db-permissions.md")]
public async Task RunAsync_WhenConnectionFails_UsesExpectedRunbook(string checkName, string expectedRunbook)
{
var check = CreateCheck(checkName);
var context = CreateContext();
var result = await check.RunAsync(context, CancellationToken.None);
Assert.Equal(DoctorSeverity.Fail, result.Severity);
Assert.NotNull(result.Remediation);
Assert.Equal(expectedRunbook, result.Remediation!.RunbookUrl);
}
private static IDoctorCheck CreateCheck(string checkName) => checkName switch
{
"connection" => new DatabaseConnectionCheck(),
"pending" => new PendingMigrationsCheck(),
"failed" => new FailedMigrationsCheck(),
"schema" => new SchemaVersionCheck(),
"pool-health" => new ConnectionPoolHealthCheck(),
"pool-size" => new ConnectionPoolSizeCheck(),
"latency" => new QueryLatencyCheck(),
"permissions" => new DatabasePermissionsCheck(),
_ => throw new ArgumentOutOfRangeException(nameof(checkName), checkName, "Unknown check")
};
private static DoctorPluginContext CreateContext()
{
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?>
{
["ConnectionStrings:DefaultConnection"] = "Host=127.0.0.1;Port=1;Database=stellaops;Username=stellaops;Password=stellaops;Timeout=1;Command Timeout=1;Pooling=false"
})
.Build();
return new DoctorPluginContext
{
Services = new EmptyServiceProvider(),
Configuration = config,
TimeProvider = TimeProvider.System,
Logger = NullLogger.Instance,
EnvironmentName = "Test",
PluginConfig = config.GetSection("Doctor:Plugins:Database")
};
}
private sealed class EmptyServiceProvider : IServiceProvider
{
public object? GetService(Type serviceType) => null;
}
}