80 lines
2.1 KiB
C#
80 lines
2.1 KiB
C#
using Shouldly;
|
|
using ZB.MOM.NatsNet.Server;
|
|
|
|
namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog;
|
|
|
|
public sealed class ConfigReloaderTests
|
|
{
|
|
[Fact] // T:2766
|
|
public void ConfigReloadBoolFlags_ShouldSucceed()
|
|
{
|
|
var options = new ServerOptions();
|
|
var errors = new List<Exception>();
|
|
var warnings = new List<Exception>();
|
|
|
|
ServerOptions.ParseCluster(
|
|
new Dictionary<string, object?>
|
|
{
|
|
["no_advertise"] = true,
|
|
["connect_backoff"] = true,
|
|
},
|
|
options,
|
|
errors,
|
|
warnings);
|
|
|
|
errors.ShouldBeEmpty();
|
|
options.Cluster.NoAdvertise.ShouldBeTrue();
|
|
options.Cluster.ConnectBackoff.ShouldBeTrue();
|
|
options.InConfig.TryGetValue("Cluster.NoAdvertise", out var explicitValue).ShouldBeTrue();
|
|
explicitValue.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseCluster_WithUnknownFieldAndStrictMode_ReturnsError()
|
|
{
|
|
ServerOptions.NoErrOnUnknownFields(false);
|
|
|
|
var options = new ServerOptions();
|
|
var errors = new List<Exception>();
|
|
|
|
ServerOptions.ParseCluster(
|
|
new Dictionary<string, object?>
|
|
{
|
|
["unknown_cluster_field"] = true,
|
|
},
|
|
options,
|
|
errors,
|
|
warnings: null);
|
|
|
|
errors.Count.ShouldBe(1);
|
|
errors[0].Message.ShouldContain("unknown field");
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseCluster_WithUnknownFieldAndRelaxedMode_IgnoresUnknownField()
|
|
{
|
|
ServerOptions.NoErrOnUnknownFields(true);
|
|
|
|
try
|
|
{
|
|
var options = new ServerOptions();
|
|
var errors = new List<Exception>();
|
|
|
|
ServerOptions.ParseCluster(
|
|
new Dictionary<string, object?>
|
|
{
|
|
["unknown_cluster_field"] = true,
|
|
},
|
|
options,
|
|
errors,
|
|
warnings: null);
|
|
|
|
errors.ShouldBeEmpty();
|
|
}
|
|
finally
|
|
{
|
|
ServerOptions.NoErrOnUnknownFields(false);
|
|
}
|
|
}
|
|
}
|