49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using DotNet.Testcontainers.Builders;
|
|
using DotNet.Testcontainers.Containers;
|
|
using Xunit;
|
|
|
|
namespace StellaOps.Router.Gateway.Tests;
|
|
|
|
public sealed class ValkeyTestcontainerFixture : IAsyncLifetime
|
|
{
|
|
private IContainer? _container;
|
|
|
|
public string ConnectionString { get; private set; } = "";
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
if (!IntegrationTestSettings.IsEnabled)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_container = new ContainerBuilder()
|
|
.WithImage("valkey/valkey:8-alpine")
|
|
.WithPortBinding(6379, true)
|
|
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(6379))
|
|
.Build();
|
|
|
|
await _container.StartAsync();
|
|
|
|
var port = _container.GetMappedPublicPort(6379);
|
|
ConnectionString = $"{_container.Hostname}:{port}";
|
|
}
|
|
|
|
public async Task DisposeAsync()
|
|
{
|
|
if (_container is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
await _container.StopAsync();
|
|
await _container.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
[CollectionDefinition(nameof(ValkeyTestcontainerCollection))]
|
|
public sealed class ValkeyTestcontainerCollection : ICollectionFixture<ValkeyTestcontainerFixture>
|
|
{
|
|
}
|
|
|