cli: populate migration module registry and tests
This commit is contained in:
@@ -1,4 +1,10 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using StellaOps.Authority.Storage.Postgres;
|
||||||
|
using StellaOps.Concelier.Storage.Postgres;
|
||||||
|
using StellaOps.Excititor.Storage.Postgres;
|
||||||
|
using StellaOps.Notify.Storage.Postgres;
|
||||||
|
using StellaOps.Policy.Storage.Postgres;
|
||||||
|
using StellaOps.Scheduler.Storage.Postgres;
|
||||||
|
|
||||||
namespace StellaOps.Cli.Services;
|
namespace StellaOps.Cli.Services;
|
||||||
|
|
||||||
@@ -17,15 +23,39 @@ public sealed record MigrationModuleInfo(
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class MigrationModuleRegistry
|
public static class MigrationModuleRegistry
|
||||||
{
|
{
|
||||||
// TODO: Wire actual module assemblies when Storage.Postgres projects are implemented
|
private static readonly List<MigrationModuleInfo> _modules =
|
||||||
// Modules will be registered as:
|
[
|
||||||
// - Authority (auth schema) - StellaOps.Authority.Storage.Postgres.AuthorityDataSource
|
new(
|
||||||
// - Scheduler (scheduler schema) - StellaOps.Scheduler.Storage.Postgres.SchedulerDataSource
|
Name: "Authority",
|
||||||
// - Concelier (vuln schema) - StellaOps.Concelier.Storage.Postgres.ConcelierDataSource
|
SchemaName: "authority",
|
||||||
// - Policy (policy schema) - StellaOps.Policy.Storage.Postgres.PolicyDataSource
|
MigrationsAssembly: typeof(AuthorityDataSource).Assembly,
|
||||||
// - Notify (notify schema) - StellaOps.Notify.Storage.Postgres.NotifyDataSource
|
ResourcePrefix: "StellaOps.Authority.Storage.Postgres.Migrations"),
|
||||||
// - Excititor (vex schema) - StellaOps.Excititor.Storage.Postgres.ExcititorDataSource
|
new(
|
||||||
private static readonly List<MigrationModuleInfo> _modules = [];
|
Name: "Scheduler",
|
||||||
|
SchemaName: "scheduler",
|
||||||
|
MigrationsAssembly: typeof(SchedulerDataSource).Assembly,
|
||||||
|
ResourcePrefix: "StellaOps.Scheduler.Storage.Postgres.Migrations"),
|
||||||
|
new(
|
||||||
|
Name: "Concelier",
|
||||||
|
SchemaName: "vuln",
|
||||||
|
MigrationsAssembly: typeof(ConcelierDataSource).Assembly,
|
||||||
|
ResourcePrefix: "StellaOps.Concelier.Storage.Postgres.Migrations"),
|
||||||
|
new(
|
||||||
|
Name: "Policy",
|
||||||
|
SchemaName: "policy",
|
||||||
|
MigrationsAssembly: typeof(PolicyDataSource).Assembly,
|
||||||
|
ResourcePrefix: "StellaOps.Policy.Storage.Postgres.Migrations"),
|
||||||
|
new(
|
||||||
|
Name: "Notify",
|
||||||
|
SchemaName: "notify",
|
||||||
|
MigrationsAssembly: typeof(NotifyDataSource).Assembly,
|
||||||
|
ResourcePrefix: "StellaOps.Notify.Storage.Postgres.Migrations"),
|
||||||
|
new(
|
||||||
|
Name: "Excititor",
|
||||||
|
SchemaName: "vex",
|
||||||
|
MigrationsAssembly: typeof(ExcititorDataSource).Assembly,
|
||||||
|
ResourcePrefix: "StellaOps.Excititor.Storage.Postgres.Migrations"),
|
||||||
|
];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all registered modules.
|
/// Gets all registered modules.
|
||||||
|
|||||||
@@ -7,30 +7,39 @@ namespace StellaOps.Cli.Tests.Commands;
|
|||||||
public class MigrationModuleRegistryTests
|
public class MigrationModuleRegistryTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Modules_Default_IsEmpty()
|
public void Modules_Populated_With_All_Postgres_Modules()
|
||||||
{
|
{
|
||||||
Assert.Empty(MigrationModuleRegistry.Modules);
|
var modules = MigrationModuleRegistry.Modules;
|
||||||
Assert.Empty(MigrationModuleRegistry.ModuleNames);
|
Assert.Equal(6, modules.Count);
|
||||||
|
Assert.Contains(modules, m => m.Name == "Authority" && m.SchemaName == "authority");
|
||||||
|
Assert.Contains(modules, m => m.Name == "Scheduler" && m.SchemaName == "scheduler");
|
||||||
|
Assert.Contains(modules, m => m.Name == "Concelier" && m.SchemaName == "vuln");
|
||||||
|
Assert.Contains(modules, m => m.Name == "Policy" && m.SchemaName == "policy");
|
||||||
|
Assert.Contains(modules, m => m.Name == "Notify" && m.SchemaName == "notify");
|
||||||
|
Assert.Contains(modules, m => m.Name == "Excititor" && m.SchemaName == "vex");
|
||||||
|
Assert.Equal(6, MigrationModuleRegistry.ModuleNames.Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void FindModule_WhenEmpty_ReturnsNull()
|
public void FindModule_Finds_By_Name_CaseInsensitive()
|
||||||
{
|
{
|
||||||
var result = MigrationModuleRegistry.FindModule("Authority");
|
var result = MigrationModuleRegistry.FindModule("authority");
|
||||||
Assert.Null(result);
|
Assert.NotNull(result);
|
||||||
|
Assert.Equal("authority", result!.SchemaName);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetModules_Filtered_WhenEmpty_ReturnsEmpty()
|
public void GetModules_Filtered_Returns_Single()
|
||||||
{
|
{
|
||||||
var result = MigrationModuleRegistry.GetModules("Authority");
|
var result = MigrationModuleRegistry.GetModules("Authority");
|
||||||
Assert.Empty(result);
|
var module = Assert.Single(result);
|
||||||
|
Assert.Equal("authority", module.SchemaName);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetModules_All_WhenEmpty_ReturnsEmpty()
|
public void GetModules_All_Returns_All()
|
||||||
{
|
{
|
||||||
var result = MigrationModuleRegistry.GetModules(null);
|
var result = MigrationModuleRegistry.GetModules(null);
|
||||||
Assert.Empty(result);
|
Assert.Equal(6, result.Count());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user