Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24ad099

Browse files
[release/10.0.1xx] Add tests for verification of expected set of Linux packages (#2773)
1 parent 7b96385 commit 24ad099

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

test/Microsoft.DotNet.Installer.Tests/LinuxInstallerTests.cs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public partial class LinuxInstallerTests : IDisposable
8181
[GeneratedRegex(@"\s*\([^)]*\)", RegexOptions.CultureInvariant)]
8282
private static partial Regex RemoveVersionConstraintRegex { get; }
8383

84+
// Remove version numbers from package names: "dotnet-runtime-10.0.0-rc.1.25480.112-x64.rpm" -> "dotnet-runtime-*-x64.rpm"
85+
[GeneratedRegex(@"\d+\.\d+\.\d+(?:-(?:rc|rtm|preview)(?:\.\d+)*)?", RegexOptions.CultureInvariant)]
86+
private static partial Regex RemoveVersionFromPackageNameRegex { get; }
87+
8488
private const string RuntimeDepsRepo = "mcr.microsoft.com/dotnet/runtime-deps";
8589
private const string RuntimeDepsVersion = "10.0-preview";
8690
private const string DotnetRuntimeDepsPrefix = "dotnet-runtime-deps-";
@@ -170,6 +174,18 @@ public async Task DebPackageMetadataTest(string repo, string tag)
170174
ValidatePackageMetadata($"{repo}:{tag}", PackageType.Deb);
171175
}
172176

177+
[ConditionalFact(typeof(LinuxInstallerTests), nameof(IncludeRpmTests))]
178+
public void ValidateRpmPackageList()
179+
{
180+
ValidatePackageList(PackageType.Rpm);
181+
}
182+
183+
[ConditionalFact(typeof(LinuxInstallerTests), nameof(IncludeDebTests))]
184+
public void ValidateDebPackageList()
185+
{
186+
ValidatePackageList(PackageType.Deb);
187+
}
188+
173189
private async Task InitializeContextAsync(PackageType packageType, bool initializeSharedContext = true)
174190
{
175191
string packageArchitecture =
@@ -712,4 +728,80 @@ private static List<string> ParseDebControlDependencies(string contents)
712728

713729
return results;
714730
}
731+
732+
private void ValidatePackageList(PackageType packageType)
733+
{
734+
string extension = packageType == PackageType.Rpm ? "*.rpm" : "*.deb";
735+
List<string> expectedPatterns = GetExpectedPackagePatterns(packageType).OrderBy(p => p).ToList();
736+
737+
// Find all packages of the specified type and normalize by removing version numbers
738+
List<string> normalizedActual = Directory.GetFiles(Config.AssetsDirectory, extension, SearchOption.AllDirectories)
739+
.Select(path => RemoveVersionFromPackageNameRegex.Replace(Path.GetFileName(path), "*"))
740+
.Distinct()
741+
.OrderBy(name => name)
742+
.ToList();
743+
744+
Assert.True(
745+
expectedPatterns.SequenceEqual(normalizedActual),
746+
$"Package list validation failed for {packageType}:\nExpected:\n{string.Join("\n", expectedPatterns)}\nActual:\n{string.Join("\n", normalizedActual)}"
747+
);
748+
}
749+
750+
private List<string> GetExpectedPackagePatterns(PackageType packageType)
751+
{
752+
string extension = packageType == PackageType.Rpm ? ".rpm" : ".deb";
753+
string arch = Config.Architecture == Architecture.X64 ? "x64" :
754+
(packageType == PackageType.Rpm ? "aarch64" : "arm64");
755+
756+
var patterns = new List<string>();
757+
758+
// Base package prefixes (common to both RPM and DEB)
759+
var basePackages = new List<string>
760+
{
761+
"aspnetcore-runtime", "aspnetcore-targeting-pack", "dotnet-apphost-pack",
762+
"dotnet-host", "dotnet-hostfxr", "dotnet-runtime", "dotnet-sdk", "dotnet-targeting-pack"
763+
};
764+
765+
// Add runtime-deps for DEB only (RPM only has distro-specific variants)
766+
if (packageType == PackageType.Deb)
767+
{
768+
basePackages.Add("dotnet-runtime-deps");
769+
}
770+
771+
// Standard variants
772+
foreach (string package in basePackages)
773+
{
774+
patterns.Add($"{package}-*-{arch}{extension}");
775+
}
776+
777+
// New key variants
778+
foreach (string package in basePackages)
779+
{
780+
patterns.Add($"{package}-*-newkey-{arch}{extension}");
781+
}
782+
783+
if (packageType == PackageType.Rpm)
784+
{
785+
// Azure Linux variants
786+
foreach (string package in basePackages)
787+
{
788+
patterns.Add($"{package}-*-azl-{arch}{extension}");
789+
}
790+
791+
// Runtime deps distro variants (RPM only)
792+
string[] distros = new[] { "azl.3", "opensuse.15", "sles.15" };
793+
foreach (string distro in distros)
794+
{
795+
patterns.Add($"dotnet-runtime-deps-*-{distro}-{arch}{extension}");
796+
797+
// `azl` deps packages do not have a -newkey- variant
798+
if (distro != "azl.3")
799+
{
800+
patterns.Add($"dotnet-runtime-deps-*-{distro}-newkey-{arch}{extension}");
801+
}
802+
}
803+
}
804+
805+
return patterns;
806+
}
715807
}

0 commit comments

Comments
 (0)