// Copyright 2020-2025 The NATS Authors // Licensed under the Apache License, Version 2.0 using Xunit.Abstractions; namespace ZB.MOM.NatsNet.Server.IntegrationTests.Helpers; /// /// Base class for integration tests that require a live NATS cluster. /// Tests are skipped when the cluster infrastructure is not available. /// [Trait("Category", "Integration")] public abstract class IntegrationTestBase { protected readonly ITestOutputHelper Output; protected IntegrationTestBase(ITestOutputHelper output) { Output = output; } /// /// Determines whether cluster integration tests should be skipped. /// Tests are skipped unless the NATS_INTEGRATION_TESTS environment variable is set to "true" /// or NATS_SERVER_URL is set to a valid cluster endpoint. /// protected static bool ShouldSkip() { var integrationEnabled = Environment.GetEnvironmentVariable("NATS_INTEGRATION_TESTS"); if (string.Equals(integrationEnabled, "true", StringComparison.OrdinalIgnoreCase)) return false; var serverUrl = Environment.GetEnvironmentVariable("NATS_SERVER_URL"); if (!string.IsNullOrEmpty(serverUrl)) return false; return true; } protected void Log(string message) => Output.WriteLine(message); }