Ports 51 tests from norace_1_test.go and 24 tests from norace_2_test.go
as [SkippableFact] integration tests. Creates test harness infrastructure
(IntegrationTestBase, CheckHelper, NatsTestClient, TestServerHelper,
TestCluster) and tags all tests with [Trait("Category", "NoRace")].
Tests skip unless NATS_INTEGRATION_ENABLED=true is set.
54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
// Copyright 2012-2025 The NATS Authors
|
|
// Licensed under the Apache License, Version 2.0
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
namespace ZB.MOM.NatsNet.Server.IntegrationTests.Helpers;
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public static class TestServerHelper
|
|
{
|
|
/// <summary>
|
|
/// Default URL for the test NATS server when running integration tests.
|
|
/// Override via NATS_TEST_SERVER_URL environment variable.
|
|
/// </summary>
|
|
public static string DefaultServerUrl =>
|
|
Environment.GetEnvironmentVariable("NATS_TEST_SERVER_URL") ?? "nats://localhost:4222";
|
|
|
|
/// <summary>
|
|
/// Stub for RunBasicJetStreamServer(t) from Go tests.
|
|
/// Returns the URL of the server to connect to.
|
|
/// Throws NotSupportedException when integration tests are not enabled.
|
|
/// </summary>
|
|
public static string RunBasicJetStreamServer(ITestOutputHelper output)
|
|
{
|
|
if (!IntegrationTestBase.IntegrationEnabled)
|
|
throw new NotSupportedException(IntegrationTestBase.SkipMessage);
|
|
|
|
output.WriteLine($"Using JetStream server at {DefaultServerUrl}");
|
|
return DefaultServerUrl;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stub for RunServer(opts) from Go tests.
|
|
/// Returns the URL of the server to connect to.
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|