mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-23 01:04:55 +01:00
Compare commits
2 Commits
ws
...
stef-aspir
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0406f642e8 | ||
|
|
11d090037e |
@@ -8,10 +8,7 @@ namespace WireMock.Net.Aspire.Tests;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
internal static class DockerUtils
|
internal static class DockerUtils
|
||||||
{
|
{
|
||||||
public static bool IsDockerRunningLinuxContainerMode()
|
public static Lazy<bool> IsDockerRunningLinuxContainerMode => new(() => IsDockerRunning() && IsLinuxContainerMode());
|
||||||
{
|
|
||||||
return IsDockerRunning() && IsLinuxContainerMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsDockerRunning()
|
private static bool IsDockerRunning()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
|
namespace WireMock.Net.Aspire.Tests.Facts;
|
||||||
|
|
||||||
|
public sealed class DockerIsRunningInLinuxContainerModeFact : FactAttribute
|
||||||
|
{
|
||||||
|
private const string SkipReason = "Docker is not running in Linux container mode. Skipping test.";
|
||||||
|
|
||||||
|
public DockerIsRunningInLinuxContainerModeFact()
|
||||||
|
{
|
||||||
|
if (!DockerUtils.IsDockerRunningLinuxContainerMode.Value)
|
||||||
|
{
|
||||||
|
Skip = SkipReason;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Projects;
|
using Projects;
|
||||||
|
using WireMock.Net.Aspire.Tests.Facts;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
namespace WireMock.Net.Aspire.Tests;
|
namespace WireMock.Net.Aspire.Tests;
|
||||||
@@ -11,15 +12,9 @@ public class IntegrationTests(ITestOutputHelper output)
|
|||||||
{
|
{
|
||||||
private record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary);
|
private record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary);
|
||||||
|
|
||||||
[Fact]
|
[DockerIsRunningInLinuxContainerModeFact]
|
||||||
public async Task StartAppHostWithWireMockAndCreateHttpClientToCallTheMockedWeatherForecastEndpoint()
|
public async Task StartAppHostWithWireMockAndCreateHttpClientToCallTheMockedWeatherForecastEndpoint()
|
||||||
{
|
{
|
||||||
if (!DockerUtils.IsDockerRunningLinuxContainerMode())
|
|
||||||
{
|
|
||||||
output.WriteLine("Docker is not running in Linux container mode. Skipping test.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
var appHostBuilder = await DistributedApplicationTestingBuilder.CreateAsync<WireMock_Net_Aspire_TestAppHost>();
|
var appHostBuilder = await DistributedApplicationTestingBuilder.CreateAsync<WireMock_Net_Aspire_TestAppHost>();
|
||||||
await using var app = await appHostBuilder.BuildAsync();
|
await using var app = await appHostBuilder.BuildAsync();
|
||||||
@@ -44,15 +39,9 @@ public class IntegrationTests(ITestOutputHelper output)
|
|||||||
weatherForecasts2.Should().HaveCount(5);
|
weatherForecasts2.Should().HaveCount(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[DockerIsRunningInLinuxContainerModeFact]
|
||||||
public async Task StartAppHostWithWireMockAndCreateWireMockAdminClientToCallTheAdminEndpoint()
|
public async Task StartAppHostWithWireMockAndCreateWireMockAdminClientToCallTheAdminEndpoint()
|
||||||
{
|
{
|
||||||
if (!DockerUtils.IsDockerRunningLinuxContainerMode())
|
|
||||||
{
|
|
||||||
output.WriteLine("Docker is not running in Linux container mode. Skipping test.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
var appHostBuilder = await DistributedApplicationTestingBuilder.CreateAsync<WireMock_Net_Aspire_TestAppHost>();
|
var appHostBuilder = await DistributedApplicationTestingBuilder.CreateAsync<WireMock_Net_Aspire_TestAppHost>();
|
||||||
await using var app = await appHostBuilder.BuildAsync();
|
await using var app = await appHostBuilder.BuildAsync();
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ namespace WireMock.Net.Tests.Facts;
|
|||||||
|
|
||||||
public sealed class IgnoreOnContinuousIntegrationFact : FactAttribute
|
public sealed class IgnoreOnContinuousIntegrationFact : FactAttribute
|
||||||
{
|
{
|
||||||
private static readonly string _skipReason = "Ignore when run via CI/CD";
|
private const string SkipReason = "Ignore when run via CI/CD";
|
||||||
private static readonly bool _isContinuousIntegrationAzure = bool.TryParse(Environment.GetEnvironmentVariable("TF_BUILD"), out var isTF) && isTF;
|
private static readonly bool IsContinuousIntegrationAzure = bool.TryParse(Environment.GetEnvironmentVariable("TF_BUILD"), out var isTF) && isTF;
|
||||||
private static readonly bool _isContinuousIntegrationGithub = bool.TryParse(Environment.GetEnvironmentVariable("GITHUB_ACTIONS"), out var isGH) && isGH;
|
private static readonly bool IsContinuousIntegrationGithub = bool.TryParse(Environment.GetEnvironmentVariable("GITHUB_ACTIONS"), out var isGH) && isGH;
|
||||||
private static bool IsContinuousIntegration() => _isContinuousIntegrationAzure || _isContinuousIntegrationGithub;
|
private static readonly bool IsContinuousIntegration = IsContinuousIntegrationAzure || IsContinuousIntegrationGithub;
|
||||||
|
|
||||||
public IgnoreOnContinuousIntegrationFact()
|
public IgnoreOnContinuousIntegrationFact()
|
||||||
{
|
{
|
||||||
if (IsContinuousIntegration())
|
if (IsContinuousIntegration)
|
||||||
{
|
{
|
||||||
Skip = _skipReason;
|
Skip = SkipReason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,22 +218,20 @@ public partial class WireMockServerTests
|
|||||||
var IPv4 = GetIPAddressesByFamily(System.Net.Sockets.AddressFamily.InterNetwork);
|
var IPv4 = GetIPAddressesByFamily(System.Net.Sockets.AddressFamily.InterNetwork);
|
||||||
var settings = new WireMockServerSettings
|
var settings = new WireMockServerSettings
|
||||||
{
|
{
|
||||||
Urls = new string[] { "http://0.0.0.0:" + port },
|
Urls = ["http://0.0.0.0:" + port],
|
||||||
};
|
};
|
||||||
var server = WireMockServer.Start(settings);
|
using var server = WireMockServer.Start(settings);
|
||||||
|
|
||||||
server.Given(Request.Create().WithPath("/*")).RespondWith(Response.Create().WithBody("x"));
|
server.Given(Request.Create().WithPath("/*")).RespondWith(Response.Create().WithBody("x"));
|
||||||
|
|
||||||
foreach (var addr in IPv4)
|
foreach (var address in IPv4)
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var response = await new HttpClient().GetStringAsync("http://" + addr + ":" + server.Ports[0] + "/foo").ConfigureAwait(false);
|
var response = await new HttpClient().GetStringAsync("http://" + address + ":" + server.Ports[0] + "/foo").ConfigureAwait(false);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.Should().Be("x");
|
response.Should().Be("x");
|
||||||
}
|
}
|
||||||
|
|
||||||
server.Stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[IgnoreOnContinuousIntegrationFact]
|
[IgnoreOnContinuousIntegrationFact]
|
||||||
@@ -244,22 +242,20 @@ public partial class WireMockServerTests
|
|||||||
var IPv6 = GetIPAddressesByFamily(System.Net.Sockets.AddressFamily.InterNetworkV6);
|
var IPv6 = GetIPAddressesByFamily(System.Net.Sockets.AddressFamily.InterNetworkV6);
|
||||||
var settings = new WireMockServerSettings
|
var settings = new WireMockServerSettings
|
||||||
{
|
{
|
||||||
Urls = new string[] { "http://0.0.0.0:" + port },
|
Urls = ["http://0.0.0.0:" + port],
|
||||||
};
|
};
|
||||||
var server = WireMockServer.Start(settings);
|
using var server = WireMockServer.Start(settings);
|
||||||
|
|
||||||
server.Given(Request.Create().WithPath("/*")).RespondWith(Response.Create().WithBody("x"));
|
server.Given(Request.Create().WithPath("/*")).RespondWith(Response.Create().WithBody("x"));
|
||||||
|
|
||||||
foreach (var addr in IPv6)
|
foreach (var address in IPv6)
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var response = await new HttpClient().GetStringAsync("http://[" + addr + "]:" + server.Ports[0] + "/foo").ConfigureAwait(false);
|
var response = await new HttpClient().GetStringAsync("http://[" + address + "]:" + server.Ports[0] + "/foo").ConfigureAwait(false);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.Should().Be("x");
|
response.Should().Be("x");
|
||||||
}
|
}
|
||||||
|
|
||||||
server.Stop();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user