test: add E2E WebSocket transport tests (connect, pub/sub round-trip)

This commit is contained in:
Joseph Doherty
2026-03-12 19:52:57 -04:00
parent 571c595d0a
commit 139b984992
2 changed files with 136 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
using NATS.Client.Core;
namespace NATS.E2E.Tests.Infrastructure;
public sealed class WebSocketServerFixture : IAsyncLifetime
{
private NatsServerProcess _server = null!;
public int Port => _server.Port;
public int WsPort { get; private set; }
public async Task InitializeAsync()
{
WsPort = NatsServerProcess.AllocateFreePort();
var config = $$"""
websocket {
listen: 127.0.0.1:{{WsPort}}
no_tls: true
}
""";
_server = NatsServerProcess.WithConfig(config);
await _server.StartAsync();
}
public async Task DisposeAsync()
{
await _server.DisposeAsync();
}
public NatsConnection CreateNatsClient()
=> new(new NatsOpts { Url = $"nats://127.0.0.1:{Port}" });
}
[CollectionDefinition("E2E-WebSocket")]
public class WebSocketCollection : ICollectionFixture<WebSocketServerFixture>;