Files
KArtSell.Aegis/tests/KArtSell.Integration.Tests/TestDatabaseConnection.cs
T
kjh2064 dc087969c5
ci / static (pull_request) Successful in 15s
ci / static (push) Successful in 13s
ci / backend (push) Successful in 3m49s
ci / frontend (push) Successful in 5m5s
Build & Test with Secrets / build (pull_request) Failing after 1s
ci / backend (pull_request) Successful in 3m55s
Build & Test with Secrets / security-scan (pull_request) Failing after 9s
ci / publish (push) Has been skipped
ci / frontend (pull_request) Successful in 5m6s
Build & Test with Secrets / frontend (pull_request) Successful in 5m2s
ci / publish (pull_request) Has been skipped
Build & Test with Secrets / notification (pull_request) Failing after 1s
CI: honor PostgreSQL service connection in integration tests
2026-08-06 15:13:20 +09:00

29 lines
1.0 KiB
C#

using System.Text.Json;
namespace KArtSell.Integration.Tests;
internal static class TestDatabaseConnection
{
public static string GetConnectionString()
{
var configured = Environment.GetEnvironmentVariable("KARTSELL_POSTGRES");
if (!string.IsNullOrWhiteSpace(configured))
return configured;
var path = Path.Combine(AppContext.BaseDirectory, "appsettings.Development.json");
if (!File.Exists(path))
throw new InvalidOperationException($"Integration test settings are required: {path}");
using var document = JsonDocument.Parse(File.ReadAllText(path));
if (!document.RootElement.TryGetProperty("ConnectionStrings", out var connectionStrings) ||
!connectionStrings.TryGetProperty("Postgres", out var postgres) ||
string.IsNullOrWhiteSpace(postgres.GetString()))
{
throw new InvalidOperationException(
"ConnectionStrings:Postgres is required in appsettings.Development.json.");
}
return postgres.GetString()!;
}
}