feat(batch5): implement jetstream error helpers and group01 constructors

This commit is contained in:
Joseph Doherty
2026-02-28 08:25:56 -05:00
parent 9fa81d472e
commit 9f30fe6033
6 changed files with 349 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
// Copyright 2020-2026 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
using System.Reflection;
using Shouldly;
namespace ZB.MOM.NatsNet.Server.Tests.JetStream;
@@ -97,4 +98,39 @@ public sealed class JetStreamErrorsTests
JsApiErrors.NewJSPeerRemapError(JsApiErrors.Unless(new Exception("other error"))),
peerRemap).ShouldBeTrue();
}
[Fact]
public void ParseOpts_WithUnlessApiErrorOption_ReturnsOverride()
{
var parseOpts = typeof(JsApiErrors).GetMethod(
"ParseOpts",
BindingFlags.NonPublic | BindingFlags.Static);
parseOpts.ShouldNotBeNull();
var expected = new JsApiError { Code = 401, ErrCode = 2048, Description = "override" };
var result = parseOpts.Invoke(
null,
[new JsApiErrors.ErrorOption[] { JsApiErrors.Unless(expected) }]);
result.ShouldBeAssignableTo<JsApiError>()
.ErrCode.ShouldBe(expected.ErrCode);
}
[Fact]
public void ToReplacerArgs_WithStringErrorAndObject_ConvertsToStringValues()
{
var toReplacerArgs = typeof(JsApiErrors).GetMethod(
"ToReplacerArgs",
BindingFlags.NonPublic | BindingFlags.Static);
toReplacerArgs.ShouldNotBeNull();
var result = toReplacerArgs.Invoke(
null,
[new object?[] { "{string}", "value", "{error}", new InvalidOperationException("boom"), "{number}", 42 }]);
result.ShouldBeAssignableTo<string[]>()
.ShouldBe(["{string}", "value", "{error}", "boom", "{number}", "42"]);
}
}