neon-sprawl/server/NeonSprawl.Server.Tests/Game/PositionState/PostgresIntegrationHarness.cs

25 lines
922 B
C#

namespace NeonSprawl.Server.Tests.Game.PositionState;
/// <summary>
/// Collection fixture: ensures Postgres is reachable (starts Docker Compose from repo root when not in CI),
/// exposes the shared <see cref="PostgresWebApplicationFactory"/>, then disposes the factory and runs
/// <c>docker compose down</c> only if this harness started Compose.
/// </summary>
public sealed class PostgresIntegrationHarness : IAsyncLifetime
{
public PostgresWebApplicationFactory Factory { get; } = new();
public async Task InitializeAsync()
{
await PostgresDockerHelper.EnsurePostgresOrStartDockerAsync(
Environment.GetEnvironmentVariable("ConnectionStrings__NeonSprawl")).ConfigureAwait(false);
}
public async Task DisposeAsync()
{
await Factory.DisposeAsync().ConfigureAwait(false);
await PostgresDockerHelper.TearDownIfWeStartedAsync().ConfigureAwait(false);
}
}