refactor: extract NATS.Server.Gateways.Tests project

Move 25 gateway-related test files from NATS.Server.Tests into a
dedicated NATS.Server.Gateways.Tests project. Update namespaces,
replace private ReadUntilAsync with SocketTestHelper from TestUtilities,
inline TestServerFactory usage, add InternalsVisibleTo, and register
the project in the solution file. All 261 tests pass.
This commit is contained in:
Joseph Doherty
2026-03-12 15:10:50 -04:00
parent a6be5e11ed
commit 9972b74bc3
29 changed files with 101 additions and 58 deletions

View File

@@ -0,0 +1,61 @@
using NATS.Server.Configuration;
namespace NATS.Server.Gateways.Tests.Gateways;
public class GatewayRemoteConfigParityBatch3Tests
{
[Fact]
public void RemoteGatewayOptions_tracks_connection_attempts_and_implicit_flag()
{
var cfg = new RemoteGatewayOptions { Name = "GW-B", Implicit = true };
cfg.IsImplicit().ShouldBeTrue();
cfg.GetConnAttempts().ShouldBe(0);
cfg.BumpConnAttempts().ShouldBe(1);
cfg.BumpConnAttempts().ShouldBe(2);
cfg.GetConnAttempts().ShouldBe(2);
cfg.ResetConnAttempts();
cfg.GetConnAttempts().ShouldBe(0);
}
[Fact]
public void RemoteGatewayOptions_add_and_update_urls_normalize_and_deduplicate()
{
var cfg = new RemoteGatewayOptions();
cfg.AddUrls(["127.0.0.1:7222", "nats://127.0.0.1:7222", "nats://127.0.0.1:7223"]);
cfg.Urls.Count.ShouldBe(2);
cfg.Urls.ShouldContain("nats://127.0.0.1:7222");
cfg.Urls.ShouldContain("nats://127.0.0.1:7223");
cfg.UpdateUrls(
configuredUrls: ["127.0.0.1:7333"],
discoveredUrls: ["nats://127.0.0.1:7334", "127.0.0.1:7333"]);
cfg.Urls.Count.ShouldBe(2);
cfg.Urls.ShouldContain("nats://127.0.0.1:7333");
cfg.Urls.ShouldContain("nats://127.0.0.1:7334");
}
[Fact]
public void RemoteGatewayOptions_save_tls_hostname_and_get_urls_helpers()
{
var cfg = new RemoteGatewayOptions
{
Urls = ["127.0.0.1:7444", "nats://localhost:7445"],
};
cfg.SaveTlsHostname("nats://gw.example.net:7522");
cfg.TlsName.ShouldBe("gw.example.net");
var urlStrings = cfg.GetUrlsAsStrings();
urlStrings.Count.ShouldBe(2);
urlStrings.ShouldContain("nats://127.0.0.1:7444");
urlStrings.ShouldContain("nats://localhost:7445");
var urls = cfg.GetUrls();
urls.Count.ShouldBe(2);
urls.ShouldContain(u => u.Authority == "127.0.0.1:7444");
urls.ShouldContain(u => u.Authority == "localhost:7445");
}
}