124 lines
3.8 KiB
C#
124 lines
3.8 KiB
C#
// -----------------------------------------------------------------------------
|
|
// DiskSpaceCheckTests.cs
|
|
// Sprint: SPRINT_20260117_025_Doctor_coverage_expansion
|
|
// Task: DOC-EXP-002 - Storage Health Check Plugin Tests
|
|
// Description: Unit tests for DiskSpaceCheck
|
|
// -----------------------------------------------------------------------------
|
|
|
|
using System.Runtime.InteropServices;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Moq;
|
|
using StellaOps.Doctor.Plugin.Storage.Checks;
|
|
using StellaOps.Doctor.Plugins;
|
|
using Xunit;
|
|
|
|
namespace StellaOps.Doctor.Plugin.Storage.Tests;
|
|
|
|
public sealed class DiskSpaceCheckTests
|
|
{
|
|
private readonly DiskSpaceCheck _check;
|
|
|
|
public DiskSpaceCheckTests()
|
|
{
|
|
_check = new DiskSpaceCheck();
|
|
}
|
|
|
|
[Fact]
|
|
public void CheckId_ReturnsExpectedValue()
|
|
{
|
|
Assert.Equal("check.storage.diskspace", _check.CheckId);
|
|
}
|
|
|
|
[Fact]
|
|
public void Tags_ContainsStorageTag()
|
|
{
|
|
Assert.Contains("storage", _check.Tags);
|
|
Assert.Contains("disk", _check.Tags);
|
|
}
|
|
|
|
[Fact]
|
|
public void CanRun_ReturnsTrue()
|
|
{
|
|
var context = CreateContext();
|
|
Assert.True(_check.CanRun(context));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RunAsync_ReturnsResult()
|
|
{
|
|
var context = CreateContext();
|
|
var result = await _check.RunAsync(context, CancellationToken.None);
|
|
|
|
Assert.NotNull(result);
|
|
Assert.Equal(_check.CheckId, result.CheckId);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RunAsync_WithValidPath_ReturnsPassOrWarn()
|
|
{
|
|
var tempDir = Path.GetTempPath();
|
|
var config = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["Storage:DataPath"] = tempDir
|
|
})
|
|
.Build();
|
|
|
|
var context = CreateContext(config);
|
|
var result = await _check.RunAsync(context, CancellationToken.None);
|
|
|
|
// Should pass or warn based on actual disk usage
|
|
Assert.True(result.Status is DoctorStatus.Pass or DoctorStatus.Warn or DoctorStatus.Fail);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RunAsync_IsDeterministic()
|
|
{
|
|
var context = CreateContext();
|
|
|
|
var result1 = await _check.RunAsync(context, CancellationToken.None);
|
|
var result2 = await _check.RunAsync(context, CancellationToken.None);
|
|
|
|
// Results should be structurally consistent
|
|
Assert.Equal(result1.CheckId, result2.CheckId);
|
|
Assert.Equal(result1.PluginId, result2.PluginId);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RunAsync_WithNonExistentPath_ReturnsSkip()
|
|
{
|
|
var config = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["Storage:DataPath"] = "/nonexistent/path/that/should/not/exist"
|
|
})
|
|
.Build();
|
|
|
|
var context = CreateContext(config);
|
|
var result = await _check.RunAsync(context, CancellationToken.None);
|
|
|
|
// Should skip if path doesn't exist (on most systems)
|
|
// Note: On Windows C:\ always exists, so this might not skip
|
|
Assert.NotNull(result);
|
|
}
|
|
|
|
private static DoctorPluginContext CreateContext(IConfiguration? config = null)
|
|
{
|
|
config ??= new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["Storage:DataPath"] = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
|
? "C:\\Windows\\Temp"
|
|
: "/tmp"
|
|
})
|
|
.Build();
|
|
|
|
var services = new Mock<IServiceProvider>();
|
|
|
|
return new DoctorPluginContext(
|
|
Configuration: config,
|
|
Services: services.Object,
|
|
CancellationToken: CancellationToken.None);
|
|
}
|
|
}
|