Skip to content

Commit

Permalink
<VersionPrefix>1.6.7-preview-02</VersionPrefix>
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Oct 6, 2024
1 parent 92a28e6 commit 4c6ed69
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>1.6.7-preview-01</VersionPrefix>
<VersionPrefix>1.6.7-preview-02</VersionPrefix>
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
31 changes: 25 additions & 6 deletions examples/WireMock.Net.TestcontainersExample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright © WireMock.Net

using DotNet.Testcontainers.Configurations;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using WireMock.Net.Testcontainers;

Expand Down Expand Up @@ -129,13 +131,16 @@ private static async Task TestCopyAsync()

await container.StartAsync();

try
{
await container.CopyAsync(@"C:\temp-wiremock\__admin\mappings\StefBodyAsFileExample.json", "/app/__admin/mappings");
}
catch (Exception e)
if (await GetImageOSAsync.Value == OSPlatform.Linux)
{
Console.WriteLine(e);
try
{
await container.CopyAsync(@"C:\temp-wiremock\__admin\mappings\StefBodyAsFileExample.json", "/app/__admin/mappings");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

Console.WriteLine("PublicUrl = " + container.GetPublicUrl());
Expand Down Expand Up @@ -205,4 +210,18 @@ private static async Task TestAsync(string? image = null)

await container.StopAsync();
}

private 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;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,8 @@

namespace WireMock.Net.Testcontainers.Utils;

internal static class PlatformUtils
internal static class ContainerUtils
{
public static OSPlatform GetCurrentOSPlatform()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return OSPlatform.Windows;
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return OSPlatform.Linux;
}

throw new NotSupportedException("The current OSPlatform is not supported.");
}

public static Lazy<Task<OSPlatform>> GetImageOSAsync = new(async () =>
{
if (TestcontainersSettings.OS.DockerEndpointAuthConfig == null)
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net.Testcontainers/WireMockContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected override ValueTask DisposeAsyncCore()

private static async Task<bool> PathStartsWithContainerMappingsPath(string value)
{
var imageOs = await PlatformUtils.GetImageOSAsync.Value;
var imageOs = await ContainerUtils.GetImageOSAsync.Value;

return value.StartsWith(ContainerInfoProvider.Info[imageOs].MappingsPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public WireMockContainerBuilder() : this(new WireMockConfiguration())
[PublicAPI]
public WireMockContainerBuilder WithImage()
{
_imageOS ??= PlatformUtils.GetImageOSAsync.Value.GetAwaiter().GetResult();
_imageOS ??= ContainerUtils.GetImageOSAsync.Value.GetAwaiter().GetResult();
return WithImage(_imageOS.Value);
}

Expand Down

0 comments on commit 4c6ed69

Please sign in to comment.