2022-01-26 14:19:04 +00:00
|
|
|
using System;
|
2022-09-26 14:15:57 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using DotNet.Testcontainers.Builders;
|
|
|
|
using DotNet.Testcontainers.Containers;
|
|
|
|
using Xunit;
|
2022-01-26 14:19:04 +00:00
|
|
|
|
|
|
|
namespace INetMock.Client.IntegrationTest;
|
|
|
|
|
2022-09-26 14:15:57 +00:00
|
|
|
public class INetMockFixture : IAsyncLifetime
|
2022-01-26 14:19:04 +00:00
|
|
|
{
|
|
|
|
private const string DefaultINetMockSocketPath = "unix:///var/run/inetmock/inetmock.sock";
|
2022-09-26 14:15:57 +00:00
|
|
|
private readonly ITestcontainersContainer _inetmockContainer;
|
|
|
|
|
|
|
|
private readonly Stream _memStream = new MemoryStream();
|
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
|
|
|
|
public INetMockFixture()
|
|
|
|
{
|
2022-09-26 14:15:57 +00:00
|
|
|
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
|
|
|
|
|
|
|
|
|
|
|
_inetmockContainer = new TestcontainersBuilder<TestcontainersContainer>()
|
|
|
|
.WithPrivileged(true)
|
|
|
|
.WithExposedPort(6767)
|
|
|
|
.WithPortBinding(6767, true)
|
|
|
|
.WithCreateContainerParametersModifier(parameters => { parameters.User = "root"; })
|
|
|
|
.WithEnvironment("INETMOCK_API_LISTEN", "tcp://0.0.0.0:6767")
|
|
|
|
.WithImage("registry.gitlab.com/inetmock/inetmock:latest")
|
|
|
|
.WithName("inetmock")
|
|
|
|
.WithWaitStrategy(Wait.ForUnixContainer().UntilOperationIsSucceeded(() =>
|
|
|
|
{
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
return true;
|
|
|
|
}, 1))
|
|
|
|
.Build();
|
|
|
|
}
|
|
|
|
|
|
|
|
public string INetMockSocketPath { get; private set; } = DefaultINetMockSocketPath;
|
|
|
|
|
|
|
|
public async Task InitializeAsync()
|
|
|
|
{
|
|
|
|
await using (_memStream)
|
2022-01-26 14:19:04 +00:00
|
|
|
{
|
2022-09-26 14:15:57 +00:00
|
|
|
await _inetmockContainer.StartAsync();
|
2022-01-26 14:19:04 +00:00
|
|
|
}
|
2022-09-26 14:15:57 +00:00
|
|
|
|
|
|
|
INetMockSocketPath = $"http://{_inetmockContainer.Hostname}:{_inetmockContainer.GetMappedPublicPort(6767)}";
|
2022-01-26 14:19:04 +00:00
|
|
|
}
|
|
|
|
|
2022-09-26 14:15:57 +00:00
|
|
|
public async Task DisposeAsync()
|
|
|
|
{
|
|
|
|
await _inetmockContainer.StopAsync();
|
|
|
|
}
|
2022-01-26 14:19:04 +00:00
|
|
|
}
|