47a7c0dde4
- cached-call retry|discard and data-connection certs list|trust|remove exit 1 when the relayed record carries success:false - bundle export probes the output path first, writes a temp file, compares the byte count, then moves it into place - bodyless / textless HTTP errors report 'HTTP <status> <reason>'; bad --trigger-config, sms update, unreadable bundle file and out-of-range --since give the JSON error envelope - numeric alarm setpoint options and --from/--to date options parse with the invariant culture (de-DE test); offset-less dates are UTC - audit export gets --timeout-seconds (default 600) for both the headers wait and the mid-stream idle deadline - debug stream retries a failed re-subscribe and exits 1 with SUBSCRIBE_FAILED if it cannot recover
38 lines
1.6 KiB
C#
38 lines
1.6 KiB
C#
using System.Net;
|
|
using ZB.MOM.WW.ScadaBridge.CLI;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests;
|
|
|
|
/// <summary>CLI-6: a bodyless or textless HTTP error must still produce a readable message.</summary>
|
|
public class ErrorMessageTests
|
|
{
|
|
/// <summary>Verifies that an empty error body synthesises "HTTP {status} {reason}".</summary>
|
|
/// <param name="code">The HTTP status.</param>
|
|
/// <param name="body">The response body.</param>
|
|
/// <param name="expected">The expected error text.</param>
|
|
[Theory]
|
|
[InlineData(502, "", "HTTP 502 Bad Gateway")]
|
|
[InlineData(307, "", "HTTP 307 Temporary Redirect")]
|
|
[InlineData(500, "{\"error\":\"\",\"code\":\"X\"}", "HTTP 500 Internal Server Error")]
|
|
[InlineData(400, "{\"error\":\"bad thing\",\"code\":\"BAD\"}", "bad thing")]
|
|
[InlineData(400, "plain text", "plain text")]
|
|
public void ToErrorResponse_NeverReturnsEmptyError(int code, string body, string expected)
|
|
{
|
|
using var response = new HttpResponseMessage((HttpStatusCode)code);
|
|
var result = ManagementHttpClient.ToErrorResponse(response, body);
|
|
|
|
Assert.Equal(expected, result.Error);
|
|
Assert.Equal(code, result.StatusCode);
|
|
Assert.Null(result.JsonData);
|
|
}
|
|
|
|
/// <summary>Verifies that the server's error code is preserved.</summary>
|
|
[Fact]
|
|
public void ToErrorResponse_KeepsServerErrorCode()
|
|
{
|
|
using var response = new HttpResponseMessage(HttpStatusCode.BadRequest);
|
|
var result = ManagementHttpClient.ToErrorResponse(response, "{\"error\":\"e\",\"code\":\"BAD\"}");
|
|
Assert.Equal("BAD", result.ErrorCode);
|
|
}
|
|
}
|