From cdc15de1947dfae9bb7f16768e6293afb094d592 Mon Sep 17 00:00:00 2001 From: Logan Bussell Date: Tue, 5 Nov 2024 10:39:05 -0800 Subject: [PATCH] Improve latest tag test --- .../StaticTagTests.cs | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/tests/Microsoft.DotNet.Docker.Tests/StaticTagTests.cs b/tests/Microsoft.DotNet.Docker.Tests/StaticTagTests.cs index 7944f7d9a4..7d07c0d69b 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/StaticTagTests.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/StaticTagTests.cs @@ -82,14 +82,17 @@ public void LatestTag_IsNotPlatformSpecific(Repo repo) [MemberData(nameof(GetTagTestObjects), TestType.Latest)] public void LatestTag_OnCorrectMajorVersion(Repo repo) { - Image latestImage = repo.Images - .Where(image => ManifestHelper.GetResolvedSharedTags(image).Contains(LatestTagValue)) + IEnumerable<(Image Image, List SharedTags)> imageDatas = repo.Images + .Select(image => (Image: image, SharedTags: ManifestHelper.GetResolvedSharedTags(image))); + + (Image Image, List SharedTags) latestImageData = imageDatas + .Where(imageData => imageData.SharedTags.Contains(LatestTagValue)) .First(); - int expectedMajorVersion = GetExpectedMajorVersion(repo); - int actualMajorVersion = GetVersion(ManifestHelper.GetResolvedProductVersion(latestImage)).Major; + int expectedMajorVersion = GetExpectedLatestMajorVersion(repo); - actualMajorVersion.Should().Be(expectedMajorVersion, "expected latest tag to be on the latest major version"); + latestImageData.SharedTags.Should().ContainMatch($"{expectedMajorVersion}.*", + because: $"latest tag should be on .NET {expectedMajorVersion} in repo {repo.Name}"); } // - -- Non-windows only for non-Appliance repos, old schema only for Appliance repos @@ -614,7 +617,7 @@ private static bool IsTagOfFormat( return GetVersion(parsedOs); } - private static int GetExpectedMajorVersion(Repo repo) + private static int GetExpectedLatestMajorVersion(Repo repo) { IEnumerable productVersions = ManifestHelper.GetResolvedProductVersions(repo); @@ -626,19 +629,14 @@ private static int GetExpectedMajorVersion(Repo repo) return GetVersion(productVersions.First()).Major; } + // In non-nightly branches, preview versions should not have the latest tag + if (!Config.IsNightlyRepo) + { + productVersions = productVersions + .Where(version => !version.Contains("-preview") && !version.Contains("-rc")); + } + return productVersions - .Where(version => - { - if (!Config.IsNightlyRepo) - { - // Use the latest GA version on the main branch - // Assumes that non-GA versions have a hyphen in them - // e.g. non GA: 5.0.0-preview.1, GA: 5.0.0 - return !version.Contains('-'); - } - // Use the latest version on the nightly branch - return true; - }) .Select(version => GetVersion(version).Major) .Max(); }