Files
natsdotnet/tests/NATS.Server.Tests/Server/CoreServerClientAccessorsParityBatch2Tests.cs
Joseph Doherty c30e67a69d Fix E2E test gaps and add comprehensive E2E + parity test suites
- Fix pull consumer fetch: send original stream subject in HMSG (not inbox)
  so NATS client distinguishes data messages from control messages
- Fix MaxAge expiry: add background timer in StreamManager for periodic pruning
- Fix JetStream wire format: Go-compatible anonymous objects with string enums,
  proper offset-based pagination for stream/consumer list APIs
- Add 42 E2E black-box tests (core messaging, auth, TLS, accounts, JetStream)
- Add ~1000 parity tests across all subsystems (gaps closure)
- Update gap inventory docs to reflect implementation status
2026-03-12 14:09:23 -04:00

96 lines
3.0 KiB
C#

using System.Net.Sockets;
using Microsoft.Extensions.Logging.Abstractions;
using NATS.Server.Auth;
using NATS.Server.Protocol;
namespace NATS.Server.Tests.Server;
public class CoreServerClientAccessorsParityBatch2Tests
{
[Fact]
public void Client_protocol_constants_match_go_values()
{
ClientProtocolVersion.ClientProtoZero.ShouldBe(0);
ClientProtocolVersion.ClientProtoInfo.ShouldBe(1);
((int)ClientConnectionType.NonClient).ShouldBe(0);
((int)ClientConnectionType.Nats).ShouldBe(1);
((int)ClientConnectionType.Mqtt).ShouldBe(2);
((int)ClientConnectionType.WebSocket).ShouldBe(3);
}
[Fact]
public void NatsClient_getters_and_client_type_behave_as_expected()
{
using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
using var stream = new MemoryStream();
var opts = new NatsOptions();
var info = new ServerInfo
{
ServerId = "srv1",
ServerName = "srv",
Version = "1.0.0",
Host = "127.0.0.1",
Port = 4222,
};
var auth = AuthService.Build(opts);
var nonce = new byte[] { 1, 2, 3 };
var stats = new ServerStats();
using var client = new NatsClient(
id: 42,
stream: stream,
socket: socket,
options: opts,
serverInfo: info,
authService: auth,
nonce: nonce,
logger: NullLogger.Instance,
serverStats: stats);
client.ClientType().ShouldBe(ClientConnectionType.Nats);
client.IsWebSocket = true;
client.ClientType().ShouldBe(ClientConnectionType.WebSocket);
client.IsWebSocket = false;
client.IsMqtt = true;
client.ClientType().ShouldBe(ClientConnectionType.Mqtt);
client.GetName().ShouldBe(string.Empty);
client.GetNonce().ShouldBe(nonce);
client.ToString().ShouldContain("cid=42");
}
[Fact]
public void NatsClient_client_type_non_client_when_kind_is_not_client()
{
using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
using var stream = new MemoryStream();
var opts = new NatsOptions();
var info = new ServerInfo
{
ServerId = "srv1",
ServerName = "srv",
Version = "1.0.0",
Host = "127.0.0.1",
Port = 4222,
};
var auth = AuthService.Build(opts);
var stats = new ServerStats();
using var routeClient = new NatsClient(
id: 7,
stream: stream,
socket: socket,
options: opts,
serverInfo: info,
authService: auth,
nonce: null,
logger: NullLogger.Instance,
serverStats: stats,
kind: ClientKind.Router);
routeClient.ClientType().ShouldBe(ClientConnectionType.NonClient);
}
}