feat(historian-gateway): reshape ServerHistorianOptions to gateway form (Endpoint/ApiKey/Tls)
Claude-Session: https://claude.ai/code/session_012SDSQ3AcaXqPcBtDESBRii
This commit is contained in:
@@ -104,9 +104,8 @@ public sealed class AddServerHistorianTests
|
||||
var config = ConfigFrom(new Dictionary<string, string?>
|
||||
{
|
||||
["ServerHistorian:Enabled"] = "true",
|
||||
["ServerHistorian:Host"] = "historian.example.com",
|
||||
["ServerHistorian:Port"] = "32569",
|
||||
["ServerHistorian:SharedSecret"] = "s",
|
||||
["ServerHistorian:Endpoint"] = "https://historian.example.com:5222",
|
||||
["ServerHistorian:ApiKey"] = "histgw_x_y",
|
||||
});
|
||||
|
||||
services.AddServerHistorian(config, (_, _) => new FakeHistorianDataSource());
|
||||
@@ -126,11 +125,10 @@ public sealed class AddServerHistorianTests
|
||||
var config = ConfigFrom(new Dictionary<string, string?>
|
||||
{
|
||||
["ServerHistorian:Enabled"] = "true",
|
||||
["ServerHistorian:Host"] = "historian.example.com",
|
||||
["ServerHistorian:Port"] = "12345",
|
||||
["ServerHistorian:Endpoint"] = "https://historian.example.com:5222",
|
||||
["ServerHistorian:ApiKey"] = "histgw_x_y",
|
||||
["ServerHistorian:UseTls"] = "true",
|
||||
["ServerHistorian:ServerCertThumbprint"] = "AABBCCDDEEFF",
|
||||
["ServerHistorian:SharedSecret"] = "s",
|
||||
["ServerHistorian:CaCertificatePath"] = "/etc/ssl/gateway-ca.pem",
|
||||
});
|
||||
|
||||
services.AddServerHistorian(config, (opts, _) =>
|
||||
@@ -143,55 +141,29 @@ public sealed class AddServerHistorianTests
|
||||
_ = provider.GetRequiredService<IHistorianDataSource>();
|
||||
|
||||
seen.ShouldNotBeNull();
|
||||
seen.Host.ShouldBe("historian.example.com");
|
||||
seen.Port.ShouldBe(12345);
|
||||
seen.Endpoint.ShouldBe("https://historian.example.com:5222");
|
||||
seen.ApiKey.ShouldBe("histgw_x_y");
|
||||
seen.UseTls.ShouldBeTrue();
|
||||
seen.ServerCertThumbprint.ShouldBe("AABBCCDDEEFF");
|
||||
seen.CaCertificatePath.ShouldBe("/etc/ssl/gateway-ca.pem");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_warns_on_empty_shared_secret_when_enabled()
|
||||
{
|
||||
var opts = new ServerHistorianOptions { Enabled = true, SharedSecret = "", Port = 32569 };
|
||||
opts.Validate().ShouldContain(w => w.Contains("SharedSecret"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_warns_on_non_positive_port_when_enabled()
|
||||
{
|
||||
var opts = new ServerHistorianOptions { Enabled = true, SharedSecret = "s", Port = 0 };
|
||||
opts.Validate().ShouldContain(w => w.Contains("Port"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_is_silent_when_correctly_configured()
|
||||
{
|
||||
new ServerHistorianOptions { Enabled = true, SharedSecret = "s", Port = 32569 }.Validate().ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_is_silent_when_disabled()
|
||||
{
|
||||
new ServerHistorianOptions { Enabled = false, SharedSecret = "", Port = 0 }.Validate().ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Section_binds_host_port_tls_fields()
|
||||
public void Section_binds_endpoint_apikey_tls_fields()
|
||||
{
|
||||
var config = ConfigFrom(new Dictionary<string, string?>
|
||||
{
|
||||
["ServerHistorian:Host"] = "historian.example.com",
|
||||
["ServerHistorian:Port"] = "12345",
|
||||
["ServerHistorian:Endpoint"] = "https://historian.example.com:5222",
|
||||
["ServerHistorian:ApiKey"] = "histgw_x_y",
|
||||
["ServerHistorian:UseTls"] = "true",
|
||||
["ServerHistorian:ServerCertThumbprint"] = "AABBCCDDEEFF",
|
||||
["ServerHistorian:CaCertificatePath"] = "/etc/ssl/gateway-ca.pem",
|
||||
});
|
||||
|
||||
var opts = config.GetSection(ServerHistorianOptions.SectionName).Get<ServerHistorianOptions>();
|
||||
|
||||
opts.ShouldNotBeNull();
|
||||
opts.Host.ShouldBe("historian.example.com");
|
||||
opts.Port.ShouldBe(12345);
|
||||
opts.Endpoint.ShouldBe("https://historian.example.com:5222");
|
||||
opts.ApiKey.ShouldBe("histgw_x_y");
|
||||
opts.UseTls.ShouldBeTrue();
|
||||
opts.ServerCertThumbprint.ShouldBe("AABBCCDDEEFF");
|
||||
opts.CaCertificatePath.ShouldBe("/etc/ssl/gateway-ca.pem");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user