feat(delmia-notifier): config loader + SCADABRIDGE_API_KEY resolution

This commit is contained in:
Joseph Doherty
2026-06-26 05:12:27 -04:00
parent 3e964acff6
commit 991c263c3e
4 changed files with 108 additions and 0 deletions
@@ -0,0 +1,50 @@
using ZB.MOM.WW.ScadaBridge.DelmiaNotifier;
namespace ZB.MOM.WW.ScadaBridge.DelmiaNotifier.Tests;
public class ConfigLoaderTests
{
[Fact]
public void SplitBaseUrls_trims_and_drops_empties()
{
var urls = ConfigLoader.SplitBaseUrls("a, b ,,c");
Assert.Equal(new[] { "a", "b", "c" }, urls);
}
[Fact]
public void SplitBaseUrls_null_or_whitespace_returns_empty()
{
Assert.Empty(ConfigLoader.SplitBaseUrls(null));
Assert.Empty(ConfigLoader.SplitBaseUrls(" "));
}
[Fact]
public void Load_defaults_timeout_to_30_when_omitted()
{
var cfg = ConfigLoader.Load("{\"ScadaBridge\":{\"BaseUrls\":\"http://x\"}}");
Assert.Equal(30, cfg.ScadaBridge.TimeoutSeconds);
Assert.Equal("http://x", cfg.ScadaBridge.BaseUrls);
}
[Fact]
public void Load_reads_all_fields()
{
var cfg = ConfigLoader.Load("{\"ScadaBridge\":{\"BaseUrls\":\"a,b\",\"TimeoutSeconds\":5,\"LogPath\":\"l.log\"}}");
Assert.Equal("a,b", cfg.ScadaBridge.BaseUrls);
Assert.Equal(5, cfg.ScadaBridge.TimeoutSeconds);
Assert.Equal("l.log", cfg.ScadaBridge.LogPath);
}
[Fact]
public void ResolveApiKey_returns_null_when_unset_or_whitespace()
{
Assert.Null(ConfigLoader.ResolveApiKey(_ => null));
Assert.Null(ConfigLoader.ResolveApiKey(_ => " "));
}
[Fact]
public void ResolveApiKey_returns_value_when_present()
{
Assert.Equal("sbk_x", ConfigLoader.ResolveApiKey(n => n == "SCADABRIDGE_API_KEY" ? "sbk_x" : null));
}
}