Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="10.0.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="10.0.300" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="10.0.301" />
<PackageVersion Include="Npgsql.DependencyInjection" Version="10.0.3" />
<PackageVersion Include="NSchema.Core" Version="5.0.0-alpha.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.7.0" />
<PackageVersion Include="NSchema.Core" Version="5.0.0-alpha.5" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.8.1" />
<PackageVersion Include="Npgsql" Version="10.0.3" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="NSubstitute" Version="6.0.0" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.13.0" />
<PackageVersion Include="Verify.XunitV3" Version="31.22.0" />
<PackageVersion Include="Verify.XunitV3" Version="31.27.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
<PackageVersion Include="xunit.v3" Version="3.2.2" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion src/NSchema.Postgres/NSchema.Postgres.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>5.0.0-alpha.4</Version>
<Version>5.0.0-alpha.5</Version>
<AssemblyVersion>$(Version.Split('-')[0])</AssemblyVersion>
<FileVersion>$(Version.Split('-')[0])</FileVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
12 changes: 8 additions & 4 deletions src/NSchema.Postgres/PostgresPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NSchema.Configuration.Plugins;
using NSchema.Plugins;
using NSchema.Plugins.Model.Config;

namespace NSchema.Postgres;

Expand Down Expand Up @@ -49,11 +49,15 @@ CONSTRAINT widgets_pkey PRIMARY KEY (id)
""";

/// <inheritdoc />
public Result Configure(NSchemaApplicationBuilder builder, PluginConfig config)
public Result Configure(NSchemaApplicationBuilder builder, PluginSettings settings)
{
var bound = config.Bind<PostgresOptions>();
var bound = settings.Get<PostgresOptions>();
if (bound.Value is not { } options)
{
return Result.From(bound.Diagnostics);
}

var diagnostics = new List<Diagnostic>(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;
Expand Down
6 changes: 3 additions & 3 deletions tests/NSchema.Postgres.Tests/PostgresPluginEndToEndTests.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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<AttributeKey, ConfigValue>
var configured = new PostgresPlugin().Configure(builder, new PluginSettings("postgres", new Dictionary<string, string?>
{
[new AttributeKey("connection_string")] = ConfigValue.OfString(_fixture.ConnectionString),
["connection_string"] = _fixture.ConnectionString,
}));
configured.IsSuccess.ShouldBeTrue();

Expand Down
29 changes: 14 additions & 15 deletions tests/NSchema.Postgres.Tests/PostgresPluginTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NSchema.Configuration.Plugins;
using NSchema.Plan.Backends;
using NSchema.Plugins;
using NSchema.Plugins.Model.Config;

namespace NSchema.Postgres.Tests;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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));
}