// Copyright 2012-2025 The NATS Authors // Licensed under the Apache License, Version 2.0 using Xunit.Abstractions; namespace ZB.MOM.NatsNet.Server.IntegrationTests.Helpers; /// /// Stub helper for creating test server instances in integration tests. /// In the Go test suite, this corresponds to RunBasicJetStreamServer(t) which /// starts an embedded NATS server with JetStream enabled. /// /// This stub is a placeholder until the .NET NATS server can be embedded /// in test scenarios. Tests using this helper will skip unless /// NATS_INTEGRATION_ENABLED=true and a server is running at the configured URL. /// public static class TestServerHelper { /// /// Default URL for the test NATS server when running integration tests. /// Override via NATS_TEST_SERVER_URL environment variable. /// public static string DefaultServerUrl => Environment.GetEnvironmentVariable("NATS_TEST_SERVER_URL") ?? "nats://localhost:4222"; /// /// Stub for RunBasicJetStreamServer(t) from Go tests. /// Returns the URL of the server to connect to. /// Throws NotSupportedException when integration tests are not enabled. /// public static string RunBasicJetStreamServer(ITestOutputHelper output) { if (!IntegrationTestBase.IntegrationEnabled) throw new NotSupportedException(IntegrationTestBase.SkipMessage); output.WriteLine($"Using JetStream server at {DefaultServerUrl}"); return DefaultServerUrl; } /// /// Stub for RunServer(opts) from Go tests. /// Returns the URL of the server to connect to. /// public static string RunServer(ITestOutputHelper output, string? url = null) { if (!IntegrationTestBase.IntegrationEnabled) throw new NotSupportedException(IntegrationTestBase.SkipMessage); var serverUrl = url ?? DefaultServerUrl; output.WriteLine($"Using server at {serverUrl}"); return serverUrl; } }