2021-02-28 11:40:40 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using DotNet.Testcontainers.Containers.Builders;
|
|
|
|
using DotNet.Testcontainers.Containers.Modules;
|
|
|
|
using DotNet.Testcontainers.Containers.WaitStrategies;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace INetMock.Client.IntegrationTest
|
|
|
|
{
|
|
|
|
public class INetMockServerFixture : IAsyncLifetime
|
|
|
|
{
|
2021-03-05 20:16:14 +00:00
|
|
|
|
2021-02-28 11:40:40 +00:00
|
|
|
private readonly TestcontainersContainer _inetmockContainer;
|
2021-03-05 20:16:14 +00:00
|
|
|
|
2021-02-28 11:40:40 +00:00
|
|
|
public INetMockServerFixture()
|
|
|
|
{
|
|
|
|
_inetmockContainer = new TestcontainersBuilder<TestcontainersContainer>()
|
|
|
|
.WithImage("inetmock-root:latest")
|
|
|
|
.WithCommand("serve")
|
|
|
|
.WithPortBinding(80, true)
|
|
|
|
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(80))
|
2021-03-05 20:16:14 +00:00
|
|
|
.WithDockerEndpoint(DockerEndpoint.DetermineFromEnv())
|
2021-02-28 11:40:40 +00:00
|
|
|
.WithMount(Path.GetTempPath(), "/var/run/inetmock")
|
|
|
|
.WithCleanUp(true)
|
|
|
|
.Build();
|
|
|
|
}
|
|
|
|
|
2021-03-05 20:16:14 +00:00
|
|
|
public Uri SocketPath => new($"unix://{Path.Join(Path.GetTempPath(), "inetmock.sock")}", UriKind.Absolute);
|
2021-02-28 11:40:40 +00:00
|
|
|
|
|
|
|
public async Task InitializeAsync()
|
|
|
|
{
|
|
|
|
await _inetmockContainer.StartAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task DisposeAsync()
|
|
|
|
{
|
|
|
|
await _inetmockContainer.StopAsync();
|
|
|
|
await _inetmockContainer.DisposeAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|