fix(tests): start container as part of test fixture
All checks were successful
agola/client-dotnet/Lint The run finished successfully
All checks were successful
agola/client-dotnet/Lint The run finished successfully
This commit is contained in:
parent
a4812683bb
commit
d8143ffd3a
3 changed files with 46 additions and 7 deletions
|
@ -22,6 +22,7 @@ runs:
|
|||
environment:
|
||||
DOCKER_HOST: tcp://127.0.0.1:2375
|
||||
INETMOCK_SOCKET: http://127.0.0.1:6767
|
||||
TESTCONTAINERS_RYUK_DISABLED: "true"
|
||||
- image: code.icb4dc0.de/prskr/ci-images/dind:latest
|
||||
privileged: true
|
||||
steps:
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||
<PackageReference Include="Testcontainers" Version="2.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
|
|
@ -1,19 +1,56 @@
|
|||
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
|
||||
public class INetMockFixture : IAsyncLifetime
|
||||
{
|
||||
private const string DefaultINetMockSocketPath = "unix:///var/run/inetmock/inetmock.sock";
|
||||
private readonly ITestcontainersContainer _inetmockContainer;
|
||||
|
||||
private readonly Stream _memStream = new MemoryStream();
|
||||
|
||||
|
||||
public INetMockFixture()
|
||||
{
|
||||
INetMockSocketPath = Environment.GetEnvironmentVariable("INETMOCK_SOCKET") ?? DefaultINetMockSocketPath;
|
||||
if (INetMockSocketPath.StartsWith("http:"))
|
||||
{
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
}
|
||||
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; }
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue