Skip to content

Commit

Permalink
[#94] #IMPLEMENT 'assemblyName: DotNet.Testcontainers; function: Dock…
Browse files Browse the repository at this point in the history
…erHostConfiguration'

{Add new property IsWindowsEngineEnabled to query running Docker engine.}
  • Loading branch information
HofmeisterAn committed Jun 15, 2019
1 parent f32beb6 commit 3fdac9b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Task("SonarBegin")
Organization = param.SonarQubeCredentials.Organization,
Branch = param.Branch,
Silent = true,
VsTestReportsPath = $"{param.Paths.Directories.TestResults}/*.trx",
VsTestReportsPath = $"{MakeAbsolute(param.Paths.Directories.TestResults)}/*.trx",
OpenCoverReportsPath = $"{MakeAbsolute(param.Paths.Directories.TestCoverage)}/coverage.opencover.xml"
});
});
Expand Down
6 changes: 2 additions & 4 deletions src/DotNet.Testcontainers.Tests/IgnoreOnLinuxEngine.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
namespace DotNet.Testcontainers.Tests
{
using System;
using System.Runtime.InteropServices;
using DotNet.Testcontainers.Core.Builder;
using Xunit;

public sealed class IgnoreOnLinuxEngine : FactAttribute
{
private static readonly bool IsWindowsEngineEnabled = "Windows_NT".Equals(Environment.GetEnvironmentVariable("AGENT_OS")); // TODO: Replace this with and Docker API call.

public IgnoreOnLinuxEngine()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !IsWindowsEngineEnabled)
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !DockerHostConfiguration.IsWindowsEngineEnabled)
{
this.Skip = "Ignore as long as Docker Windows engine is not available.";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ namespace DotNet.Testcontainers.Tests.Unit.Windows
using System.Threading.Tasks;
using DotNet.Testcontainers.Core.Builder;
using DotNet.Testcontainers.Core.Containers;
using Xunit;

public class TestcontainersContainerTest
{
[IgnoreOnLinuxEngine]
public void IsWindowsEngineEnabled()
{
Assert.True(DockerHostConfiguration.IsWindowsEngineEnabled);
}

[IgnoreOnLinuxEngine]
public async Task Disposable()
{
Expand Down
5 changes: 1 addition & 4 deletions src/DotNet.Testcontainers/Clients/MetaDataClientImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ namespace DotNet.Testcontainers.Clients

internal sealed class MetaDataClientImages : DockerMetaDataClient<ImagesListResponse>
{
private static readonly Lazy<DockerMetaDataClient<ImagesListResponse>> MetaDataClient = new Lazy<DockerMetaDataClient<ImagesListResponse>>(() =>
{
return new MetaDataClientImages();
});
private static readonly Lazy<DockerMetaDataClient<ImagesListResponse>> MetaDataClient = new Lazy<DockerMetaDataClient<ImagesListResponse>>(() => new MetaDataClientImages());

private MetaDataClientImages()
{
Expand Down
23 changes: 23 additions & 0 deletions src/DotNet.Testcontainers/Clients/MetaDataClientSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace DotNet.Testcontainers.Clients
{
using System;

internal sealed class MetaDataClientSystem : DockerApiClient
{
private static readonly Lazy<MetaDataClientSystem> MetaDataClient = new Lazy<MetaDataClientSystem>(() => new MetaDataClientSystem());

private MetaDataClientSystem()
{
}

internal static MetaDataClientSystem Instance
{
get
{
return MetaDataClient.Value;
}
}

internal bool IsWindowsEngineEnabled { get; } = "Windows_NT".Equals(Docker.System.GetSystemInfoAsync().Result.OperatingSystem);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DotNet.Testcontainers.Core.Builder
{
using DotNet.Testcontainers.Clients;

public static class DockerHostConfiguration
{
public static bool IsWindowsEngineEnabled => MetaDataClientSystem.Instance.IsWindowsEngineEnabled;
}
}

0 comments on commit 3fdac9b

Please sign in to comment.