mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-18 07:00:04 +02:00
Fix WireMockContainerBuilder (duplicate entries) (#1222)
This commit is contained in:
31
src/WireMock.Net.Testcontainers/Utils/TestcontainersUtils.cs
Normal file
31
src/WireMock.Net.Testcontainers/Utils/TestcontainersUtils.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using DotNet.Testcontainers.Configurations;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WireMock.Net.Testcontainers.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Some utility methods for containers.
|
||||
/// </summary>
|
||||
public static class TestcontainersUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the OS platform of the Docker image.
|
||||
/// </summary>
|
||||
public static Lazy<Task<OSPlatform>> GetImageOSAsync = new(async () =>
|
||||
{
|
||||
if (TestcontainersSettings.OS.DockerEndpointAuthConfig == null)
|
||||
{
|
||||
throw new InvalidOperationException($"The {nameof(TestcontainersSettings.OS.DockerEndpointAuthConfig)} is null. Check if Docker is started.");
|
||||
}
|
||||
|
||||
using var dockerClientConfig = TestcontainersSettings.OS.DockerEndpointAuthConfig.GetDockerClientConfiguration();
|
||||
using var dockerClient = dockerClientConfig.CreateClient();
|
||||
|
||||
var version = await dockerClient.System.GetVersionAsync();
|
||||
return version.Os.IndexOf("Windows", StringComparison.OrdinalIgnoreCase) >= 0 ? OSPlatform.Windows : OSPlatform.Linux;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user