test: validate grpc data connections with local docker and opcua cli
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System.Text.Json;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
|
||||
namespace GrpcDataSeed;
|
||||
|
||||
/// <summary>Nonsecret selected entity revisions before or after a fixture mutation.</summary>
|
||||
public sealed record FixtureEntityRevisions(long Connection, IReadOnlyDictionary<string, long> Mappings,
|
||||
IReadOnlyDictionary<string, long> Exports);
|
||||
|
||||
/// <summary>Audits whether a fixture mutation preserved the selected placement identities.</summary>
|
||||
public sealed record FixtureMutationRevisionReceipt(bool CredentialOnly, FixtureEntityRevisions Before, FixtureEntityRevisions After);
|
||||
|
||||
/// <summary>Keeps credential faults distinct from deliberately fenced configuration mutations.</summary>
|
||||
public static class FixtureMutationRevisions
|
||||
{
|
||||
/// <summary>Applies the fixture connection's inherited mapping consumer placement.</summary>
|
||||
public static void InheritConsumerPlacement(JsonElement mutation, DataConnection connection, RemoteNamespaceMapping mapping)
|
||||
{
|
||||
if (!IsCredentialOnly(mutation))
|
||||
mapping.ConsumerNodeIds = connection.ConsumerNodeIds.ToList();
|
||||
}
|
||||
|
||||
private static bool IsCredentialOnly(JsonElement mutation)
|
||||
{
|
||||
if (mutation.ValueKind != JsonValueKind.Object || !mutation.TryGetProperty("key_action", out var action)
|
||||
|| action.ValueKind != JsonValueKind.String
|
||||
|| action.GetString() is not ("rotate" or "rotate_staged" or "expire" or "retire_old" or "revoke")) return false;
|
||||
var fields = mutation.EnumerateObject().Select(property => property.Name).ToArray();
|
||||
return fields.Length is 1 or 2 && fields.Distinct(StringComparer.Ordinal).Count() == fields.Length
|
||||
&& fields.All(field => field is "key_action" or "key_expiry_seconds");
|
||||
}
|
||||
|
||||
/// <summary>Applies the fixture's revision policy to the actual selected tracked entities.</summary>
|
||||
public static FixtureMutationRevisionReceipt Advance(JsonElement mutation, DataConnection connection,
|
||||
IEnumerable<RemoteNamespaceMapping> mappings, IEnumerable<DataExport> exports)
|
||||
{
|
||||
var selectedMappings = mappings.ToArray();
|
||||
var selectedExports = exports.ToArray();
|
||||
FixtureEntityRevisions Capture() => new(connection.Revision,
|
||||
selectedMappings.ToDictionary(item => item.RemoteNamespaceMappingId, item => item.Revision, StringComparer.Ordinal),
|
||||
selectedExports.ToDictionary(item => item.DataExportId, item => item.Revision, StringComparer.Ordinal));
|
||||
var before = Capture();
|
||||
var credentialOnly = IsCredentialOnly(mutation);
|
||||
if (!credentialOnly)
|
||||
{
|
||||
connection.Revision++;
|
||||
foreach (var mapping in selectedMappings) mapping.Revision++;
|
||||
foreach (var export in selectedExports) export.Revision++;
|
||||
}
|
||||
return new(credentialOnly, before, Capture());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user