test: make storage guard capacity deterministic

This commit is contained in:
2026-08-18 00:52:42 +08:00
parent 4eb2c0724e
commit 60d1930447
@@ -83,13 +83,16 @@ public sealed class StorageGuardServiceTests
[Fact]
public void RedPercentageTier_DoesNotBlockFinalizeWhenAbsoluteTemporarySpaceIsAvailable()
{
var service = new StorageGuardService(
NullLogger<StorageGuardService>.Instance,
new FixedStorageCapacityProvider(totalBytes: 1_000, availableBytes: 800));
var settings = CreateSettings(enableStorageGuard: true);
settings.PauseRecordingWhenFreeSpaceBelowMegabytes = 0;
settings.ResumeRecordingWhenFreeSpaceAboveMegabytes = 0;
settings.StorageGreenThresholdPercent = 90;
settings.StorageRedThresholdPercent = 85;
var result = _service.CheckCanFinalize(settings, estimatedTemporaryBytes: 1);
var result = service.CheckCanFinalize(settings, estimatedTemporaryBytes: 1);
Assert.Equal(StorageTier.Red, result.Tier);
Assert.True(result.HasEnoughSpace);
@@ -132,4 +135,10 @@ public sealed class StorageGuardServiceTests
StorageGreenThresholdPercent = 30,
StorageRedThresholdPercent = 10
};
private sealed class FixedStorageCapacityProvider(long totalBytes, long availableBytes) : IStorageCapacityProvider
{
public StorageVolumeCapacity GetCapacity(string outputPath) =>
new(Path.GetPathRoot(outputPath) ?? "/", totalBytes, availableBytes);
}
}