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:
@@ -152,6 +152,8 @@ public sealed class StorageSizeJsonConverter : JsonConverter<long>
|
||||
|
||||
public static long Parse(string s)
|
||||
{
|
||||
// Mirrors Go getStorageSize: empty string returns 0 with no error.
|
||||
if (string.IsNullOrWhiteSpace(s)) return 0;
|
||||
if (long.TryParse(s, out var n)) return n;
|
||||
var m = Pattern.Match(s.Trim());
|
||||
if (!m.Success) throw new FormatException($"Invalid storage size: \"{s}\"");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
porting.db
BIN
porting.db
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
# NATS .NET Porting Status Report
|
||||
|
||||
Generated: 2026-02-26 23:53:55 UTC
|
||||
Generated: 2026-02-27 00:00:19 UTC
|
||||
|
||||
## Modules (12 total)
|
||||
|
||||
@@ -21,10 +21,11 @@ Generated: 2026-02-26 23:53:55 UTC
|
||||
|
||||
| Status | Count |
|
||||
|--------|-------|
|
||||
| complete | 205 |
|
||||
| complete | 208 |
|
||||
| deferred | 74 |
|
||||
| n_a | 187 |
|
||||
| not_started | 2527 |
|
||||
| stub | 224 |
|
||||
| stub | 147 |
|
||||
| verified | 114 |
|
||||
|
||||
## Library Mappings (36 total)
|
||||
@@ -36,4 +37,4 @@ Generated: 2026-02-26 23:53:55 UTC
|
||||
|
||||
## Overall Progress
|
||||
|
||||
**4190/6942 items complete (60.4%)**
|
||||
**4193/6942 items complete (60.4%)**
|
||||
|
||||
40
reports/report_8b63a6f.md
Normal file
40
reports/report_8b63a6f.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# NATS .NET Porting Status Report
|
||||
|
||||
Generated: 2026-02-27 00:00:19 UTC
|
||||
|
||||
## Modules (12 total)
|
||||
|
||||
| Status | Count |
|
||||
|--------|-------|
|
||||
| not_started | 1 |
|
||||
| verified | 11 |
|
||||
|
||||
## Features (3673 total)
|
||||
|
||||
| Status | Count |
|
||||
|--------|-------|
|
||||
| complete | 3368 |
|
||||
| n_a | 26 |
|
||||
| verified | 279 |
|
||||
|
||||
## Unit Tests (3257 total)
|
||||
|
||||
| Status | Count |
|
||||
|--------|-------|
|
||||
| complete | 208 |
|
||||
| deferred | 74 |
|
||||
| n_a | 187 |
|
||||
| not_started | 2527 |
|
||||
| stub | 147 |
|
||||
| verified | 114 |
|
||||
|
||||
## Library Mappings (36 total)
|
||||
|
||||
| Status | Count |
|
||||
|--------|-------|
|
||||
| mapped | 36 |
|
||||
|
||||
|
||||
## Overall Progress
|
||||
|
||||
**4193/6942 items complete (60.4%)**
|
||||
Reference in New Issue
Block a user