diff --git a/Directory.Packages.props b/Directory.Packages.props index cc29841..941e651 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,16 +5,16 @@ - + - - + + - + - + - + \ No newline at end of file diff --git a/src/NSchema.Postgres/NSchema.Postgres.csproj b/src/NSchema.Postgres/NSchema.Postgres.csproj index 33d8286..5935bc6 100644 --- a/src/NSchema.Postgres/NSchema.Postgres.csproj +++ b/src/NSchema.Postgres/NSchema.Postgres.csproj @@ -20,7 +20,7 @@ true true snupkg - 5.0.0-alpha.4 + 5.0.0-alpha.5 $(Version.Split('-')[0]) $(Version.Split('-')[0]) true diff --git a/src/NSchema.Postgres/PostgresPlugin.cs b/src/NSchema.Postgres/PostgresPlugin.cs index 9c9c739..991febf 100644 --- a/src/NSchema.Postgres/PostgresPlugin.cs +++ b/src/NSchema.Postgres/PostgresPlugin.cs @@ -1,5 +1,5 @@ +using NSchema.Configuration.Plugins; using NSchema.Plugins; -using NSchema.Plugins.Model.Config; namespace NSchema.Postgres; @@ -49,11 +49,15 @@ CONSTRAINT widgets_pkey PRIMARY KEY (id) """; /// - public Result Configure(NSchemaApplicationBuilder builder, PluginConfig config) + public Result Configure(NSchemaApplicationBuilder builder, PluginSettings settings) { - var bound = config.Bind(); + var bound = settings.Get(); + if (bound.Value is not { } options) + { + return Result.From(bound.Diagnostics); + } + var diagnostics = new List(bound.Diagnostics); - var options = bound.Value!; // Credentials may be supplied out of band (e.g. a secret store); the environment overrides the statement. var connectionString = Environment.GetEnvironmentVariable(EnvConnectionString) ?? options.ConnectionString; diff --git a/tests/NSchema.Postgres.Tests/PostgresPluginEndToEndTests.cs b/tests/NSchema.Postgres.Tests/PostgresPluginEndToEndTests.cs index 00a693c..028eed6 100644 --- a/tests/NSchema.Postgres.Tests/PostgresPluginEndToEndTests.cs +++ b/tests/NSchema.Postgres.Tests/PostgresPluginEndToEndTests.cs @@ -1,7 +1,7 @@ +using NSchema.Configuration.Plugins; using NSchema.Model; using NSchema.Operations; using NSchema.Plugins; -using NSchema.Plugins.Model.Config; using NSchema.Postgres.Sql; using NSchema.Postgres.Tests.Fixtures; @@ -146,9 +146,9 @@ SCRIPT backfill RUN ON ADD COLUMN {_schema}.widgets.status AS $$ private NSchemaApplication BuildApp() { var builder = NSchemaApplication.CreateBuilder(); - var configured = new PostgresPlugin().Configure(builder, new PluginConfig("postgres", new Dictionary + var configured = new PostgresPlugin().Configure(builder, new PluginSettings("postgres", new Dictionary { - [new AttributeKey("connection_string")] = ConfigValue.OfString(_fixture.ConnectionString), + ["connection_string"] = _fixture.ConnectionString, })); configured.IsSuccess.ShouldBeTrue(); diff --git a/tests/NSchema.Postgres.Tests/PostgresPluginTests.cs b/tests/NSchema.Postgres.Tests/PostgresPluginTests.cs index 6239488..e3ff10f 100644 --- a/tests/NSchema.Postgres.Tests/PostgresPluginTests.cs +++ b/tests/NSchema.Postgres.Tests/PostgresPluginTests.cs @@ -1,6 +1,6 @@ +using NSchema.Configuration.Plugins; using NSchema.Plan.Backends; using NSchema.Plugins; -using NSchema.Plugins.Model.Config; namespace NSchema.Postgres.Tests; @@ -58,7 +58,7 @@ public void Configure_ValidConnectionString_SucceedsAndRegistersProvider() { // Arrange var builder = NSchemaApplication.CreateBuilder(); - var config = Config(("connection_string", ConfigValue.OfString("Host=localhost;Database=app"))); + var config = Config(("connection_string", "Host=localhost;Database=app")); // Act var result = _sut.Configure(builder, config); @@ -90,15 +90,15 @@ public void Configure_UnknownAttribute_Fails() // Arrange var builder = NSchemaApplication.CreateBuilder(); var config = Config( - ("connection_string", ConfigValue.OfString("Host=localhost")), - ("nonsense", ConfigValue.OfString("x"))); + ("connection_string", "Host=localhost"), + ("nonsense", "x")); // Act var result = _sut.Configure(builder, config); // Assert result.IsFailure.ShouldBeTrue(); - result.Errors.ShouldContain(e => e.Message.Contains("nonsense")); + result.Errors.ShouldContain(e => e.Message.Contains("nonsense", StringComparison.OrdinalIgnoreCase)); } [Fact] @@ -107,15 +107,14 @@ public void Configure_NonIntegerCommandTimeout_Fails() // Arrange var builder = NSchemaApplication.CreateBuilder(); var config = Config( - ("connection_string", ConfigValue.OfString("Host=localhost")), - ("command_timeout", ConfigValue.OfString("soon"))); + ("connection_string", "Host=localhost"), + ("command_timeout", "soon")); // Act var result = _sut.Configure(builder, config); - // Assert + // Assert — the binder rejects a value it cannot convert to int. result.IsFailure.ShouldBeTrue(); - result.Errors.ShouldContain(e => e.Message.Contains("command_timeout")); } [Fact] @@ -124,8 +123,8 @@ public void Configure_NegativeCommandTimeout_Fails() // Arrange var builder = NSchemaApplication.CreateBuilder(); var config = Config( - ("connection_string", ConfigValue.OfString("Host=localhost")), - ("command_timeout", ConfigValue.OfInteger(-1))); + ("connection_string", "Host=localhost"), + ("command_timeout", "-1")); // Act var result = _sut.Configure(builder, config); @@ -138,9 +137,9 @@ public void Configure_NegativeCommandTimeout_Fails() [Fact] public void Configure_MultipleProblems_AggregatesEveryError() { - // Arrange — an unknown attribute and no connection string: both must be reported, not just the first. + // Arrange — no connection string and a negative timeout: both must be reported, not just the first. var builder = NSchemaApplication.CreateBuilder(); - var config = Config(("nope", ConfigValue.OfString("x"))); + var config = Config(("command_timeout", "-1")); // Act var result = _sut.Configure(builder, config); @@ -166,6 +165,6 @@ public void Configure_EnvironmentConnectionString_SatisfiesOmittedAttribute() result.Errors.ShouldBeEmpty(); } - private static PluginConfig Config(params (string Key, ConfigValue Value)[] attributes) - => new("postgres", attributes.ToDictionary(a => new AttributeKey(a.Key), a => a.Value)); + private static PluginSettings Config(params (string Key, string? Value)[] attributes) + => new("postgres", attributes.ToDictionary(a => a.Key, a => a.Value, StringComparer.OrdinalIgnoreCase)); }