work work hard work
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
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>
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user