Skip to content

Commit 0c9bdd1

Browse files
surayya-MSSurayya Huseyn Zada
authored andcommitted
check docker availability before arch support in tests
1 parent 999368f commit 0c9bdd1

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ static class ContainerCli
77
{
88
public static bool IsPodman => _isPodman.Value;
99

10+
public static bool IsAvailable => _isAvailable.Value;
11+
1012
public static RunExeCommand PullCommand(ITestOutputHelper log, params string[] args)
1113
=> CreateCommand(log, "pull", args);
1214

@@ -63,4 +65,7 @@ private static RunExeCommand CreateCommand(ITestOutputHelper log, string command
6365

6466
private static readonly Lazy<bool> _isPodman =
6567
new(() => new DockerCli(loggerFactory: new TestLoggerFactory()).GetCommand() == DockerCli.PodmanCommand);
68+
69+
private static readonly Lazy<bool> _isAvailable =
70+
new(() => new DockerCli(loggerFactory: new TestLoggerFactory()).IsAvailable());
6671
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
namespace Microsoft.NET.Build.Containers.IntegrationTests;
55

6-
public class DockerSupportsArchFactAttribute : FactAttribute
6+
public class DockerIsAvailableAndSupportsArchFactAttribute : FactAttribute
77
{
8-
private readonly string _arch;
9-
10-
public DockerSupportsArchFactAttribute(string arch)
8+
public DockerIsAvailableAndSupportsArchFactAttribute(string arch)
119
{
12-
_arch = arch;
13-
14-
if (!DockerSupportsArchHelper.DaemonSupportsArch(_arch))
10+
if (!DockerSupportsArchHelper.DaemonIsAvailable)
11+
{
12+
base.Skip = "Skipping test because Docker is not available on this host.";
13+
}
14+
else if (!DockerSupportsArchHelper.DaemonSupportsArch(arch))
1515
{
16-
base.Skip = $"Skipping test because Docker daemon does not support {_arch}.";
16+
base.Skip = $"Skipping test because Docker daemon does not support {arch}.";
1717
}
1818
}
1919
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public override IEnumerable<object[]> GetData(MethodInfo testMethod)
3434

3535
internal static class DockerSupportsArchHelper
3636
{
37+
internal static bool DaemonIsAvailable => ContainerCli.IsAvailable;
38+
3739
internal static bool DaemonSupportsArch(string arch)
3840
{
3941
// an optimization - this doesn't change over time so we can compute it once

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ public void EndToEnd_SingleArch_NoRid()
722722
processResultX64.Should().Pass().And.HaveStdOut("Hello, World!");
723723
}
724724

725-
[DockerSupportsArchFact("linux/arm64")]
725+
[DockerIsAvailableAndSupportsArchFact("linux/arm64")]
726726
public void EndToEndMultiArch_LocalRegistry()
727727
{
728728
string imageName = NewImageName();
@@ -923,7 +923,7 @@ private DirectoryInfo CreateNewProject(string template, [CallerMemberName] strin
923923
private string GetPublishArtifactsPath(string projectDir, string rid, string configuration = "Debug")
924924
=> Path.Combine(projectDir, "bin", configuration, ToolsetInfo.CurrentTargetFramework, rid, "publish");
925925

926-
[DockerSupportsArchFact("linux/arm64")]
926+
[DockerIsAvailableAndSupportsArchFact("linux/arm64")]
927927
public void EndToEndMultiArch_ArchivePublishing()
928928
{
929929
string imageName = NewImageName();
@@ -996,7 +996,7 @@ public void EndToEndMultiArch_ArchivePublishing()
996996
newProjectDir.Delete(true);
997997
}
998998

999-
[DockerSupportsArchFact("linux/arm64")]
999+
[DockerIsAvailableAndSupportsArchFact("linux/arm64")]
10001000
public void EndToEndMultiArch_RemoteRegistry()
10011001
{
10021002
string imageName = NewImageName();
@@ -1125,7 +1125,7 @@ public void EndToEndMultiArch_ContainerRuntimeIdentifiersOverridesRuntimeIdentif
11251125
newProjectDir.Delete(true);
11261126
}
11271127

1128-
[DockerSupportsArchFact("linux/arm64")]
1128+
[DockerIsAvailableAndSupportsArchFact("linux/arm64")]
11291129
public void EndToEndMultiArch_EnvVariables()
11301130
{
11311131
string imageName = NewImageName();
@@ -1192,7 +1192,7 @@ public void EndToEndMultiArch_EnvVariables()
11921192
newProjectDir.Delete(true);
11931193
}
11941194

1195-
[DockerSupportsArchFact("linux/arm64")]
1195+
[DockerIsAvailableAndSupportsArchFact("linux/arm64")]
11961196
public void EndToEndMultiArch_Ports()
11971197
{
11981198
string imageName = NewImageName();

0 commit comments

Comments
 (0)