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";
|
2023-09-15 17:01:48 +00:00
|
|
|
private readonly IContainer _inetmockContainer;
|
2022-09-26 14:15:57 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-09-15 17:01:48 +00:00
|
|
|
_inetmockContainer = new ContainerBuilder()
|
2022-09-26 14:15:57 +00:00
|
|
|
.WithPrivileged(true)
|
|
|
|
.WithExposedPort(6767)
|
|
|
|
.WithPortBinding(6767, true)
|
2023-09-15 17:01:48 +00:00
|
|
|
.WithCreateParameterModifier(parameters => { parameters.User = "root"; })
|
2022-09-26 14:15:57 +00:00
|
|
|
.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
|
|
|
}
|