fix(data): serialize portfolio publication validation
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
namespace GmRelay.Bot.Tests.Web;
|
||||
|
||||
public sealed class PortfolioSchemaGateSourceTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Compose_ShouldStartDiscordAndWebOnlyAfterBotMigrationsAreHealthy()
|
||||
{
|
||||
var compose = await ReadRepositoryFileAsync("compose.yaml");
|
||||
|
||||
AssertServiceDependsOnHealthyBot(compose, "discord");
|
||||
AssertServiceDependsOnHealthyBot(compose, "web");
|
||||
}
|
||||
|
||||
private static void AssertServiceDependsOnHealthyBot(string compose, string serviceName)
|
||||
{
|
||||
var serviceBlock = GetServiceBlock(compose, serviceName);
|
||||
|
||||
Assert.Contains(
|
||||
"""
|
||||
bot:
|
||||
condition: service_healthy
|
||||
""",
|
||||
serviceBlock,
|
||||
StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static string GetServiceBlock(string compose, string serviceName)
|
||||
{
|
||||
var lines = compose.Split('\n');
|
||||
var start = Array.FindIndex(lines, line => line.TrimEnd('\r') == $" {serviceName}:");
|
||||
Assert.True(start >= 0, $"compose.yaml should contain service '{serviceName}'.");
|
||||
|
||||
var end = Array.FindIndex(
|
||||
lines,
|
||||
start + 1,
|
||||
line => line.StartsWith(" ", StringComparison.Ordinal)
|
||||
&& !line.StartsWith(" ", StringComparison.Ordinal)
|
||||
&& line.TrimEnd('\r').EndsWith(':'));
|
||||
|
||||
return string.Join('\n', lines[start..(end < 0 ? lines.Length : end)]);
|
||||
}
|
||||
|
||||
private static async Task<string> ReadRepositoryFileAsync(string relativePath)
|
||||
{
|
||||
var directory = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
while (directory is not null)
|
||||
{
|
||||
var candidate = Path.Combine(directory.FullName, relativePath);
|
||||
if (File.Exists(candidate))
|
||||
{
|
||||
return await File.ReadAllTextAsync(candidate);
|
||||
}
|
||||
|
||||
directory = directory.Parent;
|
||||
}
|
||||
|
||||
throw new FileNotFoundException($"Could not locate repository file '{relativePath}'.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user