597d664a53
InjectAnalysisKind returns null on a null/empty trigger-config, so passing --trigger-kind strict WITHOUT --trigger-config silently dropped the kind on template script add/update and template alarm update. The CLI now detects that combination (TriggerKindWillBeIgnored) and prints a clear warning to stderr, then continues (warn-and-continue: the kind is advisory metadata, not a required field, so the entity is still created — just without the requested analysis kind). The --trigger-kind help text on all three commands now documents that it requires --trigger-config, as does the CLI README. This commit also carries the shared CLI command-builder file (Commands/TemplateCommands.cs) and README, which the same builders edit for both #257 and the #54 flag additions — the #54 message contracts/handler/UI/tests landed in the preceding commit. - TriggerKindWillBeIgnored predicate + WarnIfTriggerKindIgnored stderr warning, wired into script add/update and alarm update SetActions. - Shared option descriptions document the --trigger-config requirement. - Adds the #54 CLI flags (--min-time-between-runs, --execution-timeout-seconds) and TryParseMinTimeBetweenRuns to the same builder file. - Tests: TemplateTriggerKindIgnoredTests pins the warn predicate.
49 lines
1.8 KiB
C#
49 lines
1.8 KiB
C#
using ZB.MOM.WW.ScadaBridge.CLI.Commands;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests.Commands;
|
|
|
|
/// <summary>
|
|
/// #257: <c>--trigger-kind</c> is written into the trigger-config JSON by
|
|
/// <see cref="ZB.MOM.WW.ScadaBridge.CLI.TriggerConfigJson.InjectAnalysisKind"/>, which
|
|
/// returns null (dropping the kind) when no <c>--trigger-config</c> is supplied. Passing
|
|
/// <c>--trigger-kind</c> without <c>--trigger-config</c> was therefore a silent no-op.
|
|
/// The CLI now detects that combination (<see cref="TemplateCommands.TriggerKindWillBeIgnored"/>)
|
|
/// and warns the user (warn-and-continue, not a hard error). These tests pin the predicate.
|
|
/// </summary>
|
|
public class TemplateTriggerKindIgnoredTests
|
|
{
|
|
[Fact]
|
|
public void KindWithoutConfig_WillBeIgnored()
|
|
{
|
|
Assert.True(TemplateCommands.TriggerKindWillBeIgnored(triggerConfig: null, triggerKind: "strict"));
|
|
}
|
|
|
|
[Fact]
|
|
public void KindWithBlankConfig_WillBeIgnored()
|
|
{
|
|
Assert.True(TemplateCommands.TriggerKindWillBeIgnored(triggerConfig: " ", triggerKind: "strict"));
|
|
}
|
|
|
|
[Fact]
|
|
public void KindWithConfig_NotIgnored()
|
|
{
|
|
Assert.False(TemplateCommands.TriggerKindWillBeIgnored(
|
|
triggerConfig: "{\"expression\":\"x > 0\"}", triggerKind: "strict"));
|
|
}
|
|
|
|
[Fact]
|
|
public void NoKind_NotIgnored()
|
|
{
|
|
// No --trigger-kind at all → nothing to warn about, even without a config.
|
|
Assert.False(TemplateCommands.TriggerKindWillBeIgnored(triggerConfig: null, triggerKind: null));
|
|
Assert.False(TemplateCommands.TriggerKindWillBeIgnored(triggerConfig: null, triggerKind: " "));
|
|
}
|
|
|
|
[Fact]
|
|
public void NoKindWithConfig_NotIgnored()
|
|
{
|
|
Assert.False(TemplateCommands.TriggerKindWillBeIgnored(
|
|
triggerConfig: "{\"expression\":\"x > 0\"}", triggerKind: null));
|
|
}
|
|
}
|