Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TestcontainersTests to change network setup for Windows OS #1232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class TestcontainersUtils
/// <summary>
/// Get the OS platform of the Docker image.
/// </summary>
public static Lazy<Task<OSPlatform>> GetImageOSAsync = new(async () =>
public static Lazy<Task<OSPlatform>> GetDockerImageOSAsync = 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 TestcontainersUtils.GetImageOSAsync.Value;
var imageOs = await TestcontainersUtils.GetDockerImageOSAsync.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 ??= TestcontainersUtils.GetImageOSAsync.Value.GetAwaiter().GetResult();
_imageOS ??= TestcontainersUtils.GetDockerImageOSAsync.Value.GetAwaiter().GetResult();
return WithImage(_imageOS.Value);
}

Expand Down
2 changes: 1 addition & 1 deletion test/WireMock.Net.Tests/Facts/RunOnDockerPlatformFact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed class RunOnDockerPlatformFact : FactAttribute
{
public RunOnDockerPlatformFact(string platform)
{
if (TestcontainersUtils.GetImageOSAsync.Value.Result != OSPlatform.Create(platform))
if (TestcontainersUtils.GetDockerImageOSAsync.Value.Result != OSPlatform.Create(platform))
{
Skip = $"Only run test when Docker OS Platform {platform} is used.";
}
Expand Down
28 changes: 20 additions & 8 deletions test/WireMock.Net.Tests/Testcontainers/TestcontainersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using FluentAssertions;
using FluentAssertions.Execution;
using WireMock.Net.Testcontainers;
using WireMock.Net.Tests.Facts;
using WireMock.Net.Testcontainers.Utils;
using Xunit;

namespace WireMock.Net.Tests.Testcontainers;
Expand All @@ -30,15 +30,22 @@ public async Task WireMockContainer_Build_WithNoImage_And_StartAsync_and_StopAsy
await StartTestAndStopAsync(wireMockContainer);
}

// https://github.com/testcontainers/testcontainers-dotnet/issues/1322
[RunOnDockerPlatformFact("Linux")]

[Fact]
public async Task WireMockContainer_Build_WithNoImageAndNetwork_And_StartAsync_and_StopAsync()
{
// Act
var dummyNetwork = new NetworkBuilder()
var dummyNetworkBuilder = new NetworkBuilder()
.WithName("Dummy Network for TestcontainersTests")
.WithCleanUp(true)
.Build();
.WithCleanUp(true);

if (await IsDockerImageOSWindows())
{
// https://github.com/testcontainers/testcontainers-dotnet/issues/1322
dummyNetworkBuilder = dummyNetworkBuilder.WithCreateParameterModifier(m => m.Driver = "nat");
}

var dummyNetwork = dummyNetworkBuilder.Build();

var wireMockContainer = new WireMockContainerBuilder()
.WithNetwork(dummyNetwork)
Expand All @@ -61,7 +68,7 @@ public async Task WireMockContainer_Build_WithImage_And_StartAsync_and_StopAsync
.WithCleanUp(true)
.WithAdminUserNameAndPassword(adminUsername, adminPassword);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (await IsDockerImageOSWindows())
{
wireMockContainerBuilder = wireMockContainerBuilder.WithWindowsImage();
}
Expand All @@ -86,7 +93,7 @@ public async Task WireMockContainer_Build_WithImageAsText_And_StartAsync_and_Sto
.WithCleanUp(true)
.WithAdminUserNameAndPassword(adminUsername, adminPassword);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (await IsDockerImageOSWindows())
{
wireMockContainerBuilder = wireMockContainerBuilder.WithImage("sheyenrath/wiremock.net-windows");
}
Expand Down Expand Up @@ -123,5 +130,10 @@ private static async Task StartTestAndStopAsync(WireMockContainer wireMockContai
await wireMockContainer.StopAsync();
}
}

private static async Task<bool> IsDockerImageOSWindows()
{
return (await TestcontainersUtils.GetDockerImageOSAsync.Value) == OSPlatform.Windows;
}
}
#endif
Loading