Skip to content

Commit 2349ce5

Browse files
committed
Update tests with latest changes from nightly
1 parent 1a25b8b commit 2349ce5

File tree

10 files changed

+105
-29
lines changed

10 files changed

+105
-29
lines changed

tests/Microsoft.DotNet.Docker.Tests/AspnetImageTests.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,28 @@ public AspnetImageTests(ITestOutputHelper outputHelper)
2626
[MemberData(nameof(GetImageData))]
2727
public async Task VerifyFxDependentAppScenario(ProductImageData imageData)
2828
{
29+
if (Config.IsNightlyRepo && imageData.ImageVariant.HasFlag(DotNetImageVariant.Composite))
30+
{
31+
OutputHelper.WriteLine("Skip test due to https://github.com/dotnet/dotnet-docker/issues/4834");
32+
return;
33+
}
34+
2935
using WebScenario scenario = new WebScenario.FxDependent(imageData, DockerHelper, OutputHelper);
3036
await scenario.ExecuteAsync();
3137
}
3238

3339
[DotNetTheory]
3440
[MemberData(nameof(GetImageData))]
35-
public async Task VerifyGlobalizationScenario(ProductImageData imageData) =>
41+
public async Task VerifyGlobalizationScenario(ProductImageData imageData)
42+
{
43+
if (Config.IsNightlyRepo && imageData.ImageVariant.HasFlag(DotNetImageVariant.Composite))
44+
{
45+
OutputHelper.WriteLine("Skip test due to https://github.com/dotnet/dotnet-docker/issues/4834");
46+
return;
47+
}
48+
3649
await VerifyGlobalizationScenarioBase(imageData);
50+
}
3751

3852
[WindowsImageTheory]
3953
[MemberData(nameof(GetImageData))]
@@ -44,16 +58,22 @@ public async Task VerifyNLSScenario(ProductImageData imageData) =>
4458
[MemberData(nameof(GetImageData))]
4559
public void VerifyEnvironmentVariables(ProductImageData imageData)
4660
{
47-
List<EnvironmentVariableInfo> variables = new();
61+
List<EnvironmentVariableInfo> variables = [];
62+
63+
EnvironmentVariableInfo runtimeVersionInfo =
64+
RuntimeImageTests.GetRuntimeVersionVariableInfo(ImageRepo, imageData, DockerHelper);
4865

4966
// Skip runtime version check due to https://github.com/dotnet/dotnet-docker/issues/4834.
5067
// Re-enable when fixed.
51-
if (imageData.ImageVariant != DotNetImageVariant.Composite)
68+
if (imageData.ImageVariant.HasFlag(DotNetImageVariant.Composite))
5269
{
53-
variables.Add(RuntimeImageTests.GetRuntimeVersionVariableInfo(ImageRepo, imageData, DockerHelper));
70+
runtimeVersionInfo = runtimeVersionInfo with { AllowAnyValue = true };
5471
}
5572

56-
EnvironmentVariableInfo aspnetVersionVariableInfo = GetAspnetVersionVariableInfo(ImageRepo, imageData, DockerHelper);
73+
variables.Add(runtimeVersionInfo);
74+
75+
EnvironmentVariableInfo aspnetVersionVariableInfo =
76+
GetAspnetVersionVariableInfo(ImageRepo, imageData, DockerHelper);
5777
if (aspnetVersionVariableInfo != null)
5878
{
5979
variables.Add(aspnetVersionVariableInfo);

tests/Microsoft.DotNet.Docker.Tests/DockerHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ namespace Microsoft.DotNet.Docker.Tests
1616
{
1717
public class DockerHelper
1818
{
19-
public static string DockerOS => GetDockerOS();
19+
private static readonly Lazy<string> s_dockerOS = new(GetDockerOS);
20+
public static string DockerOS => s_dockerOS.Value;
21+
2022
public static string ContainerWorkDir => IsLinuxContainerModeEnabled ? "/sandbox" : "c:\\sandbox";
2123
public static bool IsLinuxContainerModeEnabled => string.Equals(DockerOS, "linux", StringComparison.OrdinalIgnoreCase);
2224
public static string TestArtifactsDir { get; } = Path.Combine(Directory.GetCurrentDirectory(), "TestAppArtifacts");

tests/Microsoft.DotNet.Docker.Tests/DockerfileHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public static partial class DockerfileHelper
1919
[GeneratedRegex("[A-Fa-f0-9]{64}")]
2020
public static partial Regex Sha256Regex { get; }
2121

22-
// Match versions like `1.2.3`, `1.2.3-foo.45678.9`, and `1.2.3-preview.4.56789.0`
23-
[GeneratedRegex(@"\d+\.\d+\.\d+ (-\w+(\.\d+){2,})?", RegexOptions.IgnorePatternWhitespace)]
22+
// Match versions like `1.2.3`, `1.2.3.4`, `1.2.3-foo.45678.9`, and `1.2.3-preview.4.56789.0`
23+
[GeneratedRegex(@"\d+\.\d+\.\d+(\.d+)?(-\w+(\.\d+){2,})?")]
2424
public static partial Regex VersionRegex { get; }
2525

2626
[GeneratedRegex(@"v\d+\.\d+\.\d+\.windows\.\d+")]

tests/Microsoft.DotNet.Docker.Tests/EnvironmentVariableInfo.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
using FluentAssertions;
77
using FluentAssertions.Execution;
88

9+
#nullable enable
910
namespace Microsoft.DotNet.Docker.Tests
1011
{
11-
public class EnvironmentVariableInfo
12+
public record EnvironmentVariableInfo
1213
{
13-
public bool AllowAnyValue { get; private set; }
14-
public string ExpectedValue { get; private set; }
15-
public string Name { get; private set; }
16-
public bool IsProductVersion { get; set; }
14+
public bool AllowAnyValue { get; init; } = false;
15+
public string? ExpectedValue { get; init; } = null;
16+
public string Name { get; init; }
17+
public bool IsProductVersion { get; init; } = false;
1718

1819
public EnvironmentVariableInfo(string name, string expectedValue)
1920
{

tests/Microsoft.DotNet.Docker.Tests/ImageVersion.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public readonly record struct ImageVersion
1414
public static readonly ImageVersion V8_1 = new(new Version(8, 1), isPreview: false);
1515
public static readonly ImageVersion V9_0 = new(new Version(9, 0), isPreview: false);
1616
public static readonly ImageVersion V9_0_Preview = new(new Version(9, 0), isPreview: true);
17+
public static readonly ImageVersion V10_0_Preview = new(new Version(10, 0), isPreview: true);
1718

1819
public ImageVersion(Version version, bool isPreview)
1920
{

tests/Microsoft.DotNet.Docker.Tests/OS.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public static class OS
2020
// Debian
2121
public const string Bookworm = "bookworm";
2222
public const string BookwormSlim = $"{Bookworm}{SlimSuffix}";
23+
public const string Trixie = "trixie";
24+
public const string TrixieSlim = $"{Trixie}{SlimSuffix}";
2325

2426
// Mariner
2527
public const string Mariner = "cbl-mariner";

tests/Microsoft.DotNet.Docker.Tests/ProductImageData.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public record ProductImageData : ImageData
2020

2121
public bool GlobalizationInvariantMode => !SupportsGlobalization;
2222

23+
// PowerShell does not support Arm-based Alpine, skip testing
24+
// https://github.com/PowerShell/PowerShell/issues/14667
25+
// https://github.com/PowerShell/PowerShell/issues/12937
26+
public bool SupportsPowerShell => !(OS.Contains("alpine") && IsArm);
27+
2328
public string SdkOS
2429
{
2530
get => HasCustomSdk ? _sdkOS : OS;

tests/Microsoft.DotNet.Docker.Tests/ProductImageTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,15 @@ private static IEnumerable<string> GetAotDepsPackages(ProductImageData imageData
390390
"libssl3",
391391
"tzdata",
392392
],
393+
{ OS: OS.TrixieSlim } =>
394+
[
395+
"ca-certificates",
396+
"libc6",
397+
"libgcc-s1",
398+
"libicu72",
399+
"libssl3t64",
400+
"tzdata",
401+
],
393402
_ => throw new NotSupportedException()
394403
};
395404

tests/Microsoft.DotNet.Docker.Tests/RuntimeDepsImageTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,46 @@ public void VerifyDistrolessOSReleaseInfo(ProductImageData imageData)
121121
Assert.NotEmpty(GetOSReleaseInfo(imageData, ImageRepo, DockerHelper));
122122
}
123123

124+
/// <summary>
125+
/// Verifies the presence of the Chisel manifest in Ubuntu Chiseled images. Chisel manifest documentation:
126+
/// https://discourse.ubuntu.com/t/chisel-manifest-is-supported-in-newly-released-v1-0-0/48944
127+
/// </summary>
128+
[LinuxImageTheory]
129+
[MemberData(nameof(GetImageData))]
130+
public void VerifyChiselManifest(ProductImageData imageData)
131+
{
132+
if (!imageData.OS.Contains(OS.ChiseledSuffix))
133+
{
134+
OutputHelper.WriteLine("Test is only relevant to Ubuntu Chiseled images");
135+
return;
136+
}
137+
138+
// https://github.com/dotnet/dotnet-docker/issues/5973#issuecomment-2501510550
139+
bool shouldContainManifest = imageData.Version.Major != 8 && imageData.Version.Major != 9;
140+
141+
const string RootFs = "/rootfs";
142+
const string ChiselManifestFileName = "/var/lib/chisel/manifest.wall";
143+
144+
// Setup a distroless helper image to inspect the filesystem of the Chiseled image
145+
string distrolessHelperImageTag = DockerHelper.BuildDistrolessHelper(ImageRepo, imageData, RootFs);
146+
147+
// Check for the presence of the Chisel manifest by listing the files in the directory
148+
// and then verifying the output.
149+
string actualOutput = DockerHelper.Run(
150+
image: distrolessHelperImageTag,
151+
name: imageData.GetIdentifier(nameof(VerifyChiselManifest)),
152+
command: $"find {RootFs}/var/lib/ -path *chisel* -type f");
153+
154+
if (shouldContainManifest)
155+
{
156+
Assert.Contains(ChiselManifestFileName, actualOutput);
157+
}
158+
else
159+
{
160+
Assert.DoesNotContain(ChiselManifestFileName, actualOutput);
161+
}
162+
}
163+
124164
private static string GetOSReleaseInfo(
125165
ProductImageData imageData,
126166
DotNetImageRepo imageRepo,

tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@ public SdkImageTests(ITestOutputHelper outputHelper)
3232

3333
protected override DotNetImageRepo ImageRepo => DotNetImageRepo.SDK;
3434

35-
private static bool IsPowerShellSupported(ProductImageData imageData, out string reason)
36-
{
37-
if (imageData.OS.Contains("alpine") && imageData.IsArm)
38-
{
39-
reason = "PowerShell does not support Arm-based Alpine, skip testing (https://github.com/PowerShell/PowerShell/issues/14667, https://github.com/PowerShell/PowerShell/issues/12937)";
40-
return false;
41-
}
42-
43-
reason = "";
44-
return true;
45-
}
46-
4735
public static IEnumerable<object[]> GetImageData()
4836
{
4937
return TestData.GetImageData(DotNetImageRepo.SDK)
@@ -101,7 +89,6 @@ public void VerifyEnvironmentVariables(ProductImageData imageData)
10189
new EnvironmentVariableInfo("DOTNET_GENERATE_ASPNET_CERTIFICATE", "false"),
10290
new EnvironmentVariableInfo("DOTNET_USE_POLLING_FILE_WATCHER", "true"),
10391
new EnvironmentVariableInfo("NUGET_XMLDOC_MODE", "skip"),
104-
new EnvironmentVariableInfo("POWERSHELL_DISTRIBUTION_CHANNEL", allowAnyValue: true),
10592
new EnvironmentVariableInfo("DOTNET_SDK_VERSION", version)
10693
{
10794
IsProductVersion = true
@@ -112,6 +99,13 @@ public void VerifyEnvironmentVariables(ProductImageData imageData)
11299
..GetCommonEnvironmentVariables(),
113100
];
114101

102+
if (imageData.SupportsPowerShell
103+
|| imageData.Version == ImageVersion.V8_0
104+
|| imageData.Version == ImageVersion.V9_0)
105+
{
106+
variables.Add(new EnvironmentVariableInfo("POWERSHELL_DISTRIBUTION_CHANNEL", allowAnyValue: true));
107+
}
108+
115109
if (imageData.SdkOS.StartsWith(OS.Alpine))
116110
{
117111
variables.Add(new EnvironmentVariableInfo("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "false"));
@@ -355,15 +349,17 @@ private string GetSdkUrl(ProductImageData imageData)
355349

356350
private void PowerShellScenario_Execute(ProductImageData imageData, string optionalArgs)
357351
{
358-
if (!IsPowerShellSupported(imageData, out string powershellReason))
352+
string image = imageData.GetImage(DotNetImageRepo.SDK, DockerHelper);
353+
354+
if (!imageData.SupportsPowerShell)
359355
{
360-
OutputHelper.WriteLine(powershellReason);
356+
OutputHelper.WriteLine($"PowerShell is not supproted on {image}");
361357
return;
362358
}
363359

364360
// A basic test which executes an arbitrary command to validate PS is functional
365361
string output = DockerHelper.Run(
366-
image: imageData.GetImage(DotNetImageRepo.SDK, DockerHelper),
362+
image: image,
367363
name: imageData.GetIdentifier($"pwsh"),
368364
optionalRunArgs: optionalArgs,
369365
command: $"pwsh -c (Get-Childitem env:DOTNET_RUNNING_IN_CONTAINER).Value"

0 commit comments

Comments
 (0)