using Grpc.Core;
using Mishima.Nexus.Wire.V1;
namespace Robotico.Nexus.Client.Tests.TestSupport;
///
/// Sentinel logical-database names (sent via the x-nexus-database metadata header) that let
/// tests deterministically drive the failure branches of Ping-fronted RPCs without a real
/// unreachable engine.
///
public static class FakeNexusTriggers
{
/// Ping succeeds at the transport level but the engine reports a non-OK status.
public const string PingReportsFailure = "trigger-ping-status-failure";
/// Ping fails at the transport level (simulated ).
public const string PingThrows = "trigger-ping-rpc-exception";
/// Returns a failure when the request's database header is , or throws when it is .
public static NexusStatus? TryStatusFailure(ServerCallContext context)
{
string? database = context.RequestHeaders.GetValue(NexusCallMetadata.DatabaseKey);
if (string.Equals(database, PingThrows, StringComparison.Ordinal))
{
throw new RpcException(new Status(StatusCode.Unavailable, "Simulated transport failure."));
}
return string.Equals(database, PingReportsFailure, StringComparison.Ordinal)
? NexusStatuses.Failure("NXS_UNAVAILABLE", "Simulated engine-reported failure.")
: null;
}
}