fix(cli): resolve CLI-002..007 — robust response rendering, URL/JSON arg validation, credential env-vars, doc refresh
This commit is contained in:
98
tests/ScadaLink.CLI.Tests/InstanceArgumentParsingTests.cs
Normal file
98
tests/ScadaLink.CLI.Tests/InstanceArgumentParsingTests.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using ScadaLink.CLI.Commands;
|
||||
|
||||
namespace ScadaLink.CLI.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Regression tests for CLI-005 — malformed <c>--bindings</c> / <c>--overrides</c> JSON
|
||||
/// previously threw unhandled exceptions instead of producing a clean validation error.
|
||||
/// </summary>
|
||||
public class InstanceArgumentParsingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ParseBindings_ValidJson_ReturnsPairs()
|
||||
{
|
||||
var ok = InstanceCommands.TryParseBindings(
|
||||
"[[\"Speed\", 5], [\"Mode\", 7]]", out var bindings, out var error);
|
||||
|
||||
Assert.True(ok);
|
||||
Assert.Null(error);
|
||||
Assert.Equal(2, bindings!.Count);
|
||||
Assert.Equal(("Speed", 5), bindings[0]);
|
||||
Assert.Equal(("Mode", 7), bindings[1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseBindings_MalformedJson_ReturnsErrorNotException()
|
||||
{
|
||||
var ok = InstanceCommands.TryParseBindings("not json", out var bindings, out var error);
|
||||
|
||||
Assert.False(ok);
|
||||
Assert.Null(bindings);
|
||||
Assert.NotNull(error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseBindings_ShortPair_ReturnsErrorNotException()
|
||||
{
|
||||
// A pair with fewer than two elements previously threw ArgumentOutOfRangeException.
|
||||
var ok = InstanceCommands.TryParseBindings("[[\"Speed\"]]", out var bindings, out var error);
|
||||
|
||||
Assert.False(ok);
|
||||
Assert.Null(bindings);
|
||||
Assert.NotNull(error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseBindings_WrongElementTypes_ReturnsErrorNotException()
|
||||
{
|
||||
// A non-string name / non-int id previously threw InvalidOperationException.
|
||||
var ok = InstanceCommands.TryParseBindings("[[5, \"Speed\"]]", out var bindings, out var error);
|
||||
|
||||
Assert.False(ok);
|
||||
Assert.Null(bindings);
|
||||
Assert.NotNull(error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseBindings_JsonNull_ReturnsErrorNotException()
|
||||
{
|
||||
var ok = InstanceCommands.TryParseBindings("null", out var bindings, out var error);
|
||||
|
||||
Assert.False(ok);
|
||||
Assert.Null(bindings);
|
||||
Assert.NotNull(error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseOverrides_ValidJson_ReturnsDictionary()
|
||||
{
|
||||
var ok = InstanceCommands.TryParseOverrides(
|
||||
"{\"Speed\": \"100\", \"Mode\": null}", out var overrides, out var error);
|
||||
|
||||
Assert.True(ok);
|
||||
Assert.Null(error);
|
||||
Assert.Equal(2, overrides!.Count);
|
||||
Assert.Equal("100", overrides["Speed"]);
|
||||
Assert.Null(overrides["Mode"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseOverrides_MalformedJson_ReturnsErrorNotException()
|
||||
{
|
||||
var ok = InstanceCommands.TryParseOverrides("{bad json", out var overrides, out var error);
|
||||
|
||||
Assert.False(ok);
|
||||
Assert.Null(overrides);
|
||||
Assert.NotNull(error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseOverrides_JsonNull_ReturnsErrorNotException()
|
||||
{
|
||||
var ok = InstanceCommands.TryParseOverrides("null", out var overrides, out var error);
|
||||
|
||||
Assert.False(ok);
|
||||
Assert.Null(overrides);
|
||||
Assert.NotNull(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user