test: add E2E MQTT bridge tests (pub/sub, different-topic isolation, QoS 1)
This commit is contained in:
50
tests/NATS.E2E.Tests/Infrastructure/MqttServerFixture.cs
Normal file
50
tests/NATS.E2E.Tests/Infrastructure/MqttServerFixture.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using NATS.Client.Core;
|
||||
|
||||
namespace NATS.E2E.Tests.Infrastructure;
|
||||
|
||||
public sealed class MqttServerFixture : IAsyncLifetime
|
||||
{
|
||||
private NatsServerProcess _server = null!;
|
||||
private string _storeDir = null!;
|
||||
|
||||
public int Port => _server.Port;
|
||||
public int MqttPort { get; private set; }
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
MqttPort = NatsServerProcess.AllocateFreePort();
|
||||
_storeDir = Path.Combine(Path.GetTempPath(), "nats-e2e-mqtt-" + Guid.NewGuid().ToString("N")[..8]);
|
||||
Directory.CreateDirectory(_storeDir);
|
||||
|
||||
var config = $$"""
|
||||
jetstream {
|
||||
store_dir: "{{_storeDir}}"
|
||||
max_mem_store: 64mb
|
||||
max_file_store: 256mb
|
||||
}
|
||||
mqtt {
|
||||
listen: 127.0.0.1:{{MqttPort}}
|
||||
}
|
||||
""";
|
||||
|
||||
_server = NatsServerProcess.WithConfig(config);
|
||||
await _server.StartAsync();
|
||||
}
|
||||
|
||||
public async Task DisposeAsync()
|
||||
{
|
||||
await _server.DisposeAsync();
|
||||
|
||||
if (_storeDir is not null && Directory.Exists(_storeDir))
|
||||
{
|
||||
try { Directory.Delete(_storeDir, recursive: true); }
|
||||
catch (IOException ex) { _ = ex; /* best-effort temp dir cleanup */ }
|
||||
}
|
||||
}
|
||||
|
||||
public NatsConnection CreateNatsClient()
|
||||
=> new(new NatsOpts { Url = $"nats://127.0.0.1:{Port}" });
|
||||
}
|
||||
|
||||
[CollectionDefinition("E2E-Mqtt")]
|
||||
public class MqttCollection : ICollectionFixture<MqttServerFixture>;
|
||||
Reference in New Issue
Block a user