|
| 1 | +using SimpleZipDrive.Core.Models; |
| 2 | +using SimpleZipDrive.Mounting; |
| 3 | + |
| 4 | +namespace SimpleZipDrive.Tests; |
| 5 | + |
| 6 | +/// <summary> |
| 7 | +/// Tests for <see cref="MountBackendAvailability" />: effective-backend resolution, the |
| 8 | +/// availability probe, and the user-facing names and download pages used by the startup |
| 9 | +/// driver warning. |
| 10 | +/// </summary> |
| 11 | +public class MountBackendAvailabilityTests |
| 12 | +{ |
| 13 | + [Theory] |
| 14 | + [InlineData(MountBackend.Dokan)] |
| 15 | + [InlineData(MountBackend.WinFsp)] |
| 16 | + [InlineData(MountBackend.Fuse)] |
| 17 | + public void ResolveEffective_ExplicitBackend_IsReturnedUnchanged(MountBackend backend) |
| 18 | + { |
| 19 | + Assert.Equal(backend, MountBackendAvailability.ResolveEffective(backend)); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public void ResolveEffective_Auto_MatchesPlatformPreference() |
| 24 | + { |
| 25 | + var resolved = MountBackendAvailability.ResolveEffective(MountBackend.Auto); |
| 26 | + |
| 27 | + if (OperatingSystem.IsWindows()) |
| 28 | + { |
| 29 | + Assert.Contains(resolved, new[] { MountBackend.Dokan, MountBackend.WinFsp }); |
| 30 | + } |
| 31 | + else |
| 32 | + { |
| 33 | + Assert.Equal(MountBackend.Fuse, resolved); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + [Fact] |
| 38 | + public void IsAvailable_FuseOnWindows_ReturnsFalseWithReason() |
| 39 | + { |
| 40 | + if (!OperatingSystem.IsWindows()) return; |
| 41 | + |
| 42 | + Assert.False(MountBackendAvailability.IsAvailable(MountBackend.Fuse, out var reason)); |
| 43 | + Assert.False(string.IsNullOrWhiteSpace(reason)); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void IsAvailable_UnknownBackend_ReturnsFalseWithReason() |
| 48 | + { |
| 49 | + Assert.False(MountBackendAvailability.IsAvailable((MountBackend)99, out var reason)); |
| 50 | + Assert.Contains("Unknown mount backend", reason, StringComparison.OrdinalIgnoreCase); |
| 51 | + } |
| 52 | + |
| 53 | + [Theory] |
| 54 | + [InlineData(MountBackend.Dokan, "Dokan")] |
| 55 | + [InlineData(MountBackend.WinFsp, "WinFsp")] |
| 56 | + [InlineData(MountBackend.Fuse, "FUSE")] |
| 57 | + public void DisplayName_ReturnsExpectedName(MountBackend backend, string expected) |
| 58 | + { |
| 59 | + Assert.Equal(expected, MountBackendAvailability.DisplayName(backend)); |
| 60 | + } |
| 61 | + |
| 62 | + [Theory] |
| 63 | + [InlineData(MountBackend.Dokan, "Dokan driver")] |
| 64 | + [InlineData(MountBackend.WinFsp, "WinFsp driver")] |
| 65 | + public void DriverName_WindowsDrivers_ReturnsExpectedName(MountBackend backend, string expected) |
| 66 | + { |
| 67 | + Assert.Equal(expected, MountBackendAvailability.DriverName(backend)); |
| 68 | + } |
| 69 | + |
| 70 | + [Fact] |
| 71 | + public void DriverName_Fuse_MatchesPlatform() |
| 72 | + { |
| 73 | + var expected = OperatingSystem.IsMacOS() ? "macFUSE" : "libfuse3"; |
| 74 | + Assert.Equal(expected, MountBackendAvailability.DriverName(MountBackend.Fuse)); |
| 75 | + } |
| 76 | + |
| 77 | + [Theory] |
| 78 | + [InlineData(MountBackend.Dokan, "https://github.com/dokan-dev/dokany/releases")] |
| 79 | + [InlineData(MountBackend.WinFsp, "https://github.com/winfsp/winfsp/releases")] |
| 80 | + public void DownloadUrl_WindowsDrivers_ReturnsOfficialPage(MountBackend backend, string expected) |
| 81 | + { |
| 82 | + Assert.Equal(expected, MountBackendAvailability.DownloadUrl(backend)); |
| 83 | + } |
| 84 | + |
| 85 | + [Fact] |
| 86 | + public void DownloadUrl_Fuse_MatchesPlatform() |
| 87 | + { |
| 88 | + var url = MountBackendAvailability.DownloadUrl(MountBackend.Fuse); |
| 89 | + |
| 90 | + if (OperatingSystem.IsMacOS()) |
| 91 | + Assert.Equal("https://macfuse.github.io/", url); |
| 92 | + else |
| 93 | + Assert.Contains("installation", url, StringComparison.OrdinalIgnoreCase); |
| 94 | + } |
| 95 | + |
| 96 | + [Fact] |
| 97 | + public void DefaultMountBackend_IsDokanOnWindowsAndAutoElsewhere() |
| 98 | + { |
| 99 | + var expected = OperatingSystem.IsWindows() ? MountBackend.Dokan : MountBackend.Auto; |
| 100 | + Assert.Equal(expected, AppSettings.DefaultMountBackend); |
| 101 | + } |
| 102 | + |
| 103 | + [Fact] |
| 104 | + public void NormalizeMountBackend_PlatformInvalidValue_IsMappedToAvailableBackend() |
| 105 | + { |
| 106 | + if (OperatingSystem.IsWindows()) |
| 107 | + { |
| 108 | + // FUSE is not offered on Windows; it falls back to the Windows default (Dokan). |
| 109 | + Assert.Equal(AppSettings.DefaultMountBackend, AppSettings.NormalizeMountBackend(MountBackend.Fuse)); |
| 110 | + Assert.Equal(MountBackend.Dokan, AppSettings.NormalizeMountBackend(MountBackend.Dokan)); |
| 111 | + Assert.Equal(MountBackend.WinFsp, AppSettings.NormalizeMountBackend(MountBackend.WinFsp)); |
| 112 | + Assert.Equal(MountBackend.Auto, AppSettings.NormalizeMountBackend(MountBackend.Auto)); |
| 113 | + } |
| 114 | + else |
| 115 | + { |
| 116 | + // Dokan/WinFsp are not offered on Linux/macOS; they fall back to FUSE. |
| 117 | + Assert.Equal(MountBackend.Fuse, AppSettings.NormalizeMountBackend(MountBackend.Dokan)); |
| 118 | + Assert.Equal(MountBackend.Fuse, AppSettings.NormalizeMountBackend(MountBackend.WinFsp)); |
| 119 | + Assert.Equal(MountBackend.Fuse, AppSettings.NormalizeMountBackend(MountBackend.Fuse)); |
| 120 | + Assert.Equal(MountBackend.Auto, AppSettings.NormalizeMountBackend(MountBackend.Auto)); |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments