fix unit tests for windows-only logic

This commit is contained in:
rmcrackan
2026-05-25 10:41:20 -04:00
parent f8c5f0da68
commit 6bd1ea7ca4
2 changed files with 15 additions and 3 deletions

View File

@@ -64,10 +64,11 @@ public static class DiskSpaceHelper
/// <summary>
/// Strips the Win32 extended-length prefix so <see cref="DriveInfo"/> and path APIs see a normal root.
/// No-op on non-Windows platforms (Libation only uses the prefix there).
/// </summary>
public static string NormalizePathForDriveQuery(string path)
{
if (!path.StartsWith(WinLongPathPrefix, StringComparison.Ordinal))
if (!OperatingSystem.IsWindows() || !path.StartsWith(WinLongPathPrefix, StringComparison.Ordinal))
return path;
var stripped = path[WinLongPathPrefix.Length..];

View File

@@ -33,18 +33,29 @@ public class DiskSpaceHelperTests
}
[TestMethod]
public void NormalizePathForDriveQuery_strips_extended_prefix()
[OSCondition(OperatingSystems.Windows)]
public void Windows_NormalizePathForDriveQuery_strips_extended_prefix()
{
Assert.AreEqual(@"C:\Audiobooks\Books", DiskSpaceHelper.NormalizePathForDriveQuery(@"\\?\C:\Audiobooks\Books"));
Assert.AreEqual(@"\\server\share\Books", DiskSpaceHelper.NormalizePathForDriveQuery(@"\\?\UNC\server\share\Books"));
}
[TestMethod]
public void GetPathRootForDiskSpaceCheck_strips_extended_prefix()
[OSCondition(OperatingSystems.Windows)]
public void Windows_GetPathRootForDiskSpaceCheck_strips_extended_prefix()
{
Assert.AreEqual(@"C:\", DiskSpaceHelper.GetPathRootForDiskSpaceCheck(@"\\?\C:\Audiobooks\Books"));
}
[TestMethod]
public void GetPathRootForDiskSpaceCheck_unix_absolute_path()
{
if (OperatingSystem.IsWindows())
Assert.Inconclusive("Skipped because OS is Windows.");
Assert.AreEqual("/", DiskSpaceHelper.GetPathRootForDiskSpaceCheck("/home/user/Libation/Books"));
}
[TestMethod]
public void GetRequiredBytesForDriveUsage_uses_batch_for_books_only()
{