refactor(runtime): case-insensitive ClusterId/NodeId match + suppress short-circuit + edge tests (review)
This commit is contained in:
@@ -109,7 +109,7 @@ public static class DeploymentArtifact
|
|||||||
{
|
{
|
||||||
if (el.ValueKind != JsonValueKind.Object) continue;
|
if (el.ValueKind != JsonValueKind.Object) continue;
|
||||||
var nid = el.TryGetProperty("NodeId", out var nEl) ? nEl.GetString() : null;
|
var nid = el.TryGetProperty("NodeId", out var nEl) ? nEl.GetString() : null;
|
||||||
if (!string.Equals(nid, nodeId, StringComparison.Ordinal)) continue;
|
if (!string.Equals(nid, nodeId, StringComparison.OrdinalIgnoreCase)) continue;
|
||||||
myCluster = el.TryGetProperty("ClusterId", out var cEl) ? cEl.GetString() : null;
|
myCluster = el.TryGetProperty("ClusterId", out var cEl) ? cEl.GetString() : null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -136,14 +136,11 @@ public static class DeploymentArtifact
|
|||||||
public static IReadOnlyList<DriverInstanceSpec> ParseDriverInstances(ReadOnlySpan<byte> blob, string nodeId)
|
public static IReadOnlyList<DriverInstanceSpec> ParseDriverInstances(ReadOnlySpan<byte> blob, string nodeId)
|
||||||
{
|
{
|
||||||
var scope = ResolveClusterScope(blob, nodeId);
|
var scope = ResolveClusterScope(blob, nodeId);
|
||||||
|
if (scope.Mode == ClusterFilterMode.Suppress) return Array.Empty<DriverInstanceSpec>();
|
||||||
var all = ParseDriverInstances(blob);
|
var all = ParseDriverInstances(blob);
|
||||||
return scope.Mode switch
|
return scope.Mode == ClusterFilterMode.ScopeTo
|
||||||
{
|
? all.Where(s => string.Equals(s.ClusterId, scope.ClusterId, StringComparison.OrdinalIgnoreCase)).ToArray()
|
||||||
ClusterFilterMode.Suppress => Array.Empty<DriverInstanceSpec>(),
|
: all;
|
||||||
ClusterFilterMode.ScopeTo => all.Where(
|
|
||||||
s => string.Equals(s.ClusterId, scope.ClusterId, StringComparison.Ordinal)).ToArray(),
|
|
||||||
_ => all,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DriverInstanceSpec? TryReadSpec(JsonElement el)
|
private static DriverInstanceSpec? TryReadSpec(JsonElement el)
|
||||||
|
|||||||
@@ -295,4 +295,38 @@ public sealed class DeploymentArtifactTests
|
|||||||
|
|
||||||
specs.Single().DriverInstanceId.ShouldBe("DI-ok");
|
specs.Single().DriverInstanceId.ShouldBe("DI-ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Verifies that a malformed blob resolves to None rather than throwing.</summary>
|
||||||
|
[Fact]
|
||||||
|
public void ResolveClusterScope_malformed_blob_returns_None()
|
||||||
|
{
|
||||||
|
var scope = DeploymentArtifact.ResolveClusterScope("not json"u8.ToArray(), "central-1:4053");
|
||||||
|
scope.Mode.ShouldBe(ClusterFilterMode.None);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Verifies that a blank ClusterId in the node row resolves to Suppress.</summary>
|
||||||
|
[Fact]
|
||||||
|
public void ResolveClusterScope_blank_cluster_id_suppresses()
|
||||||
|
{
|
||||||
|
var blob = BlobOf(new
|
||||||
|
{
|
||||||
|
Clusters = new[] { new { ClusterId = "MAIN" }, new { ClusterId = "SITE-A" } },
|
||||||
|
Nodes = new[] { new { NodeId = "central-1:4053", ClusterId = "" } },
|
||||||
|
});
|
||||||
|
DeploymentArtifact.ResolveClusterScope(blob, "central-1:4053").Mode.ShouldBe(ClusterFilterMode.Suppress);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Verifies that NodeId matching in ResolveClusterScope is case-insensitive.</summary>
|
||||||
|
[Fact]
|
||||||
|
public void ResolveClusterScope_node_id_match_is_case_insensitive()
|
||||||
|
{
|
||||||
|
var blob = BlobOf(new
|
||||||
|
{
|
||||||
|
Clusters = new[] { new { ClusterId = "MAIN" }, new { ClusterId = "SITE-A" } },
|
||||||
|
Nodes = new[] { new { NodeId = "Central-1:4053", ClusterId = "MAIN" } },
|
||||||
|
});
|
||||||
|
var scope = DeploymentArtifact.ResolveClusterScope(blob, "central-1:4053");
|
||||||
|
scope.Mode.ShouldBe(ClusterFilterMode.ScopeTo);
|
||||||
|
scope.ClusterId.ShouldBe("MAIN");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user