Skip to content

Commit 999368f

Browse files
Surayya Huseyn ZadaSurayya Huseyn Zada
authored andcommitted
fix test EndToEndMultiArch_LocalRegistry
1 parent 6b147e1 commit 999368f

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/ContainerCli.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static RunExeCommand LoadCommand(ITestOutputHelper log, params string[] a
3737
public static RunExeCommand PortCommand(ITestOutputHelper log, string containerName, int port)
3838
=> CreateCommand(log, "port", containerName, port.ToString());
3939

40+
public static RunExeCommand ImagesCommand(ITestOutputHelper log, params string[] args)
41+
=> CreateCommand(log, "images", args);
42+
4043
private static RunExeCommand CreateCommand(ITestOutputHelper log, string command, params string[] args)
4144
{
4245
string commandPath = IsPodman ? "podman" : "docker";

src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/EndToEndTests.cs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,8 @@ public void EndToEnd_SingleArch_NoRid()
726726
public void EndToEndMultiArch_LocalRegistry()
727727
{
728728
string imageName = NewImageName();
729-
string imageTag = "1.0";
730-
string imageX64 = $"{imageName}:{imageTag}-linux-x64";
731-
string imageArm64 = $"{imageName}:{imageTag}-linux-arm64";
729+
string tag = "1.0";
730+
string image = $"{imageName}:{tag}";
732731

733732
// Create a new console project
734733
DirectoryInfo newProjectDir = CreateNewProject("console");
@@ -741,7 +740,7 @@ public void EndToEndMultiArch_LocalRegistry()
741740
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
742741
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
743742
$"/p:ContainerRepository={imageName}",
744-
$"/p:ContainerImageTag={imageTag}",
743+
$"/p:ContainerImageTag={tag}",
745744
"/p:EnableSdkContainerSupport=true")
746745
.WithWorkingDirectory(newProjectDir.FullName)
747746
.Execute();
@@ -752,33 +751,53 @@ public void EndToEndMultiArch_LocalRegistry()
752751
commandResult.Should().Pass()
753752
.And.HaveStdOutContaining(GetPublishArtifactsPath(newProjectDir.FullName, "linux-x64"))
754753
.And.HaveStdOutContaining(GetPublishArtifactsPath(newProjectDir.FullName, "linux-arm64"))
755-
.And.HaveStdOutContaining($"Pushed image '{imageX64}' to local registry")
756-
.And.HaveStdOutContaining($"Pushed image '{imageArm64}' to local registry")
757-
.And.NotHaveStdOutContaining("Pushed image index");
754+
.And.HaveStdOutContaining($"Building image '{imageName}' for runtime identifier 'linux-x64'")
755+
.And.HaveStdOutContaining($"Building image '{imageName}' for runtime identifier 'linux-arm64'")
756+
.And.HaveStdOutContaining($"Pushed image '{image}' to local registry");
757+
758+
//Multi-arch oci images that are loaded to docker can only be run by their image id
759+
string imageId = GetImageId(image);
758760

759761
// Check that the containers can be run
760762
CommandResult processResultX64 = ContainerCli.RunCommand(
761763
_testOutput,
762764
"--rm",
765+
"--platform",
766+
"linux/amd64",
763767
"--name",
764768
$"test-container-{imageName}-x64",
765-
imageX64)
769+
imageId)
766770
.Execute();
767771
processResultX64.Should().Pass().And.HaveStdOut("Hello, World!");
768772

769773
CommandResult processResultArm64 = ContainerCli.RunCommand(
770774
_testOutput,
771775
"--rm",
776+
"--platform",
777+
"linux/arm64",
772778
"--name",
773779
$"test-container-{imageName}-arm64",
774-
imageArm64)
780+
imageId)
775781
.Execute();
776782
processResultArm64.Should().Pass().And.HaveStdOut("Hello, World!");
777783

778784
// Cleanup
779785
newProjectDir.Delete(true);
780786
}
781787

788+
private string GetImageId(string image)
789+
{
790+
CommandResult commandResult = ContainerCli.ImagesCommand(_testOutput, "--format", "\"{{.ID}}\"", image)
791+
.Execute();
792+
commandResult.Should().Pass();
793+
794+
var output = commandResult.StdOut.Split("\n").Select(s => s.Trim('"')).ToList();
795+
796+
output.Should().NotBeNullOrEmpty().And.OnlyContain(s => s == output[0]);
797+
798+
return output[0];
799+
}
800+
782801
[DockerAvailableFact]
783802
public void MultiArchStillAllowsSingleRID()
784803
{

0 commit comments

Comments
 (0)