using Microsoft.Extensions.Logging.Abstractions;
using NATS.Server.Configuration;

namespace NATS.Server.Gateways.Tests;

public class GatewayLeafBootstrapTests
{
    [Fact]
    public async Task Server_bootstraps_gateway_and_leaf_managers_when_configured()
    {
        var options = new NatsOptions
        {
            Host = "127.0.0.1",
            Port = 0,
            Gateway = new GatewayOptions
            {
                Name = "G1",
                Host = "127.0.0.1",
                Port = 0,
            },
            LeafNode = new LeafNodeOptions
            {
                Host = "127.0.0.1",
                Port = 0,
            },
        };

        var server = new NatsServer(options, NullLoggerFactory.Instance);
        var cts = new CancellationTokenSource();
        _ = server.StartAsync(cts.Token);
        await server.WaitForReadyAsync();

        try
        {
            server.Stats.Gateways.ShouldBeGreaterThanOrEqualTo(0);
            server.Stats.Leafs.ShouldBeGreaterThanOrEqualTo(0);
        }
        finally
        {
            await cts.CancelAsync();
            server.Dispose();
            cts.Dispose();
        }
    }
}
