From 6bd1ea7ca462538b7398ebf9b399b1b0acfbdeaa Mon Sep 17 00:00:00 2001 From: rmcrackan Date: Mon, 25 May 2026 10:41:20 -0400 Subject: [PATCH] fix unit tests for windows-only logic --- Source/LibationFileManager/DiskSpaceHelper.cs | 3 ++- .../DiskSpaceHelperTests.cs | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/LibationFileManager/DiskSpaceHelper.cs b/Source/LibationFileManager/DiskSpaceHelper.cs index a3d56949..264ff55c 100644 --- a/Source/LibationFileManager/DiskSpaceHelper.cs +++ b/Source/LibationFileManager/DiskSpaceHelper.cs @@ -64,10 +64,11 @@ public static class DiskSpaceHelper /// /// Strips the Win32 extended-length prefix so and path APIs see a normal root. + /// No-op on non-Windows platforms (Libation only uses the prefix there). /// 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..]; diff --git a/Source/_Tests/LibationFileManager.Tests/DiskSpaceHelperTests.cs b/Source/_Tests/LibationFileManager.Tests/DiskSpaceHelperTests.cs index 84ab8371..8ca06593 100644 --- a/Source/_Tests/LibationFileManager.Tests/DiskSpaceHelperTests.cs +++ b/Source/_Tests/LibationFileManager.Tests/DiskSpaceHelperTests.cs @@ -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() {