namespace MoShiro.Measurement.Tests; public sealed class PlatformDetectorTests { [Theory] [InlineData("PRETTY_NAME=\"Debian GNU/Linux 12 (bookworm)\"|NAME=\"Debian GNU/Linux\"|VERSION_ID=\"12\"|ID=debian", "Debian 12")] [InlineData("NAME=\"OpenWrt\"|VERSION_ID=\"24.10.0\"|ID=openwrt", "OpenWrt 24.10")] [InlineData("NAME=\"Alpine Linux\"|ID=alpine|VERSION_ID=3.22.1", "Alpine Linux 3.22")] [InlineData("NAME=\"Ubuntu\"|VERSION_ID=\"24.04\"", "Ubuntu 24.04")] [InlineData("ID=arch", "arch")] [InlineData("", "Linux")] public void LinuxName_IsTheDistroAndItsMajorMinorVersion(string osRelease, string expected) { Assert.Equal(expected, PlatformDetector.LinuxName(osRelease.Split('|', StringSplitOptions.RemoveEmptyEntries))); } [Fact] public void Detect_ReportsOnlyCoarseInformation() { var platform = PlatformDetector.Detect(); Assert.Contains(platform.Os, new[] { "linux", "windows", "macos", "other" }); Assert.Contains(platform.Arch, new[] { "x64", "arm64", "arm", "x86" }); // 没有主机名、内核版本:名字很短,也不含小数点以外的版本细节 Assert.True((platform.Name ?? string.Empty).Length < 40); Assert.DoesNotContain(Environment.MachineName, platform.Name ?? string.Empty, StringComparison.OrdinalIgnoreCase); } }