feat(p7-02): fill opts_test.go stubs — ServerOptionsTests

Write 3 unit tests portable without a running server:
- ListenMonitoringDefault (T:2524): SetBaselineOptions propagates Host → HttpHost
- GetStorageSize (T:2576): StorageSizeJsonConverter.Parse K/M/G/T suffixes
- ClusterNameAndGatewayNameConflict (T:2571): ValidateOptions returns ErrClusterNameConfigConflict

Mark 74 opts_test.go stubs deferred: tests require either the NATS
conf-format parser (not yet ported), a running server (RunServer/NewServer),
or CLI flag-parsing infrastructure (ConfigureOptions).

Fix StorageSizeJsonConverter.Parse to return 0 for empty input,
matching Go getStorageSize("") == (0, nil).

Total unit tests: 638 passing.
This commit is contained in:
Joseph Doherty
2026-02-26 19:00:18 -05:00
parent 8b63a6f6c2
commit f0b4138459
5 changed files with 98 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
using Shouldly;
using ZB.MOM.NatsNet.Server;
using ZB.MOM.NatsNet.Server.Config;
namespace ZB.MOM.NatsNet.Server.Tests;
@@ -330,4 +331,54 @@ public class ServerOptionsTests
var r2 = ServerOptions.MergeOptions(null, flagOpts);
r2.Port.ShouldBe(5678);
}
/// <summary>
/// Mirrors TestListenMonitoringDefault — when Host is set without HTTPHost,
/// SetBaselineOptions should copy Host to HTTPHost.
/// </summary>
[Fact] // T:2524
public void ListenMonitoringDefault_ShouldSetHttpHostToHost()
{
var opts = new ServerOptions { Host = "10.0.1.22" };
opts.SetBaselineOptions();
opts.Host.ShouldBe("10.0.1.22");
opts.HttpHost.ShouldBe("10.0.1.22");
opts.Port.ShouldBe(ServerConstants.DefaultPort);
}
/// <summary>
/// Mirrors TestGetStorageSize — StorageSizeJsonConverter.Parse converts K/M/G/T suffixes
/// and returns 0 for empty input; invalid suffixes throw.
/// </summary>
[Fact] // T:2576
public void GetStorageSize_ShouldParseSuffixes()
{
StorageSizeJsonConverter.Parse("1K").ShouldBe(1024L);
StorageSizeJsonConverter.Parse("1M").ShouldBe(1048576L);
StorageSizeJsonConverter.Parse("1G").ShouldBe(1073741824L);
StorageSizeJsonConverter.Parse("1T").ShouldBe(1099511627776L);
StorageSizeJsonConverter.Parse("").ShouldBe(0L);
Should.Throw<FormatException>(() => StorageSizeJsonConverter.Parse("1L"));
Should.Throw<FormatException>(() => StorageSizeJsonConverter.Parse("TT"));
}
/// <summary>
/// Mirrors TestClusterNameAndGatewayNameConflict — when Cluster.Name != Gateway.Name,
/// ValidateOptions should return ErrClusterNameConfigConflict.
/// </summary>
[Fact] // T:2571
public void ClusterNameAndGatewayNameConflict_ShouldReturnConflictError()
{
var opts = new ServerOptions
{
Cluster = new ClusterOpts { Name = "A", Port = -1 },
Gateway = new GatewayOpts { Name = "B", Port = -1 },
};
var err = NatsServer.ValidateOptions(opts);
err.ShouldNotBeNull();
err.ShouldBe(ServerErrors.ErrClusterNameConfigConflict);
}
}