55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using DotNet.Testcontainers.Builders;
|
|
using DotNet.Testcontainers.Containers;
|
|
using Xunit;
|
|
|
|
namespace INetMock.Client.IntegrationTest;
|
|
|
|
public class INetMockFixture : IAsyncLifetime
|
|
{
|
|
private const string DefaultINetMockSocketPath = "unix:///var/run/inetmock/inetmock.sock";
|
|
private readonly IContainer _inetmockContainer;
|
|
|
|
private readonly Stream _memStream = new MemoryStream();
|
|
|
|
|
|
public INetMockFixture()
|
|
{
|
|
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
|
|
|
_inetmockContainer = new ContainerBuilder()
|
|
.WithPrivileged(true)
|
|
.WithExposedPort(6767)
|
|
.WithPortBinding(6767, true)
|
|
.WithCreateParameterModifier(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)
|
|
{
|
|
await _inetmockContainer.StartAsync();
|
|
}
|
|
|
|
INetMockSocketPath = $"http://{_inetmockContainer.Hostname}:{_inetmockContainer.GetMappedPublicPort(6767)}";
|
|
}
|
|
|
|
public async Task DisposeAsync()
|
|
{
|
|
await _inetmockContainer.StopAsync();
|
|
}
|
|
}
|