Files
natsnet/dotnet/tests/ZB.MOM.NatsNet.Server.IntegrationTests/Helpers/ConfigHelper.cs
Joseph Doherty 8db4fccc95 test(batch50): port 118 JetStream cluster 1 integration tests
Ports the first 118 tests from golang/nats-server/server/jetstream_cluster_1_test.go
to C# integration tests in JetStream/JetStreamCluster1Tests.cs. Adds the
Helpers/ scaffold (IntegrationTestBase, TestCluster, NatsTestClient, CheckHelper,
ConfigHelper) and Xunit.SkippableFact package; tests skip automatically unless
NATS_INTEGRATION_TESTS=true is set.
2026-03-01 12:14:55 -05:00

67 lines
1.7 KiB
C#

// Copyright 2020-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0
namespace ZB.MOM.NatsNet.Server.IntegrationTests.Helpers;
/// <summary>
/// Provides configuration templates and file helpers for integration tests.
/// Mirrors Go's <c>jsClusterTempl</c>, <c>jsClusterAccountsTempl</c>, etc.
/// </summary>
public static class ConfigHelper
{
/// <summary>
/// Standard JetStream cluster configuration template.
/// Use <c>%s</c> placeholders for server_name, store_dir, cluster_name, port, and routes.
/// </summary>
public const string JsClusterTemplate = @"
listen: 127.0.0.1:-1
server_name: %s
jetstream: {max_mem_store: 256MB, max_file_store: 2GB, store_dir: '%s'}
cluster {
name: %s
listen: 127.0.0.1:%d
routes = [%s]
}
";
/// <summary>
/// JetStream cluster template with accounts.
/// </summary>
public const string JsClusterAccountsTemplate = @"
listen: 127.0.0.1:-1
server_name: %s
jetstream: {max_mem_store: 256MB, max_file_store: 2GB, store_dir: '%s'}
accounts {
$SYS {
users: [{user: admin, password: s3cr3t!}]
}
ONE {
jetstream: enabled
users: [{user: one, password: p}]
}
TWO {
jetstream: enabled
users: [{user: two, password: p}]
}
}
cluster {
name: %s
listen: 127.0.0.1:%d
routes = [%s]
}
";
/// <summary>
/// Creates a temporary config file with the given content and returns its path.
/// </summary>
public static string CreateConfigFile(string content)
{
var path = Path.Combine(Path.GetTempPath(), $"nats-test-{Guid.NewGuid():N}.conf");
File.WriteAllText(path, content);
return path;
}
}