test: validate grpc data connections with local docker and opcua cli
This commit is contained in:
+11
-6
@@ -129,22 +129,26 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
internal LocalDataFixture(int additionalRawNodes = 0,
|
||||
Func<DataAuthenticatedContext, IDataSubscriptionService>? subscriptions = null,
|
||||
Func<DataAuthenticatedContext, DataTarget, IDataSubscriptionService>? targetSubscriptions = null,
|
||||
bool advanceAuthority = false, string role = "Primary", long servingGeneration = 0, bool nestedCatalog = false, bool nestedUnsCatalog = false)
|
||||
bool advanceAuthority = false, string role = "Primary", long servingGeneration = 0, bool nestedCatalog = false, bool nestedUnsCatalog = false,
|
||||
Func<DataAuthenticatedContext, IDataWriteService>? writes = null, bool denyReadExport = false,
|
||||
ManualTimeProvider? clock = null, string servingNode = "node-a", string servingIncarnation = "serving-1")
|
||||
{
|
||||
Serving = Serving with { Role = role, ServingGeneration = servingGeneration };
|
||||
if (clock is not null) Clock = clock;
|
||||
Serving = Serving with { NodeId = servingNode, Incarnation = servingIncarnation, Role = role, ServingGeneration = servingGeneration };
|
||||
Ticket = new(SourceKey.ForDriver("cluster", "driver", "Plant/Driver/Device/Speed", servingNode, servingIncarnation), new(1, 1));
|
||||
Hub = HubTest.Create(clock: Clock, bytes: 1_000_000);
|
||||
Hub.TryBind(Ticket).ShouldBeTrue();
|
||||
var key = new ApiKey { ApiKeyId = "peer-key", Name = "peer-key", Principal = "peer", SecretHash = "hash", Enabled = true };
|
||||
Authority.Apply("cluster", "first", [key],
|
||||
[new NodeAcl { NodeAclId = "grant", ClusterId = "cluster", Principal = "peer",
|
||||
ScopeKind = nestedUnsCatalog ? NodeAclScopeKind.Cluster : NodeAclScopeKind.RawFolder,
|
||||
ScopeId = nestedUnsCatalog ? null : "folder", PermissionFlags = NodePermissions.ReadOnly }],
|
||||
ScopeId = nestedUnsCatalog ? null : "folder", PermissionFlags = writes is null ? NodePermissions.ReadOnly : NodePermissions.Operator }],
|
||||
new Dictionary<AclScopeRef, IReadOnlyList<NodeAclPath>> { [new(NodeAclScopeKind.RawFolder, "folder")] = [new(["raw", "Plant"])] });
|
||||
if (advanceAuthority)
|
||||
{
|
||||
Authority.Apply("cluster", "second", [key],
|
||||
[new NodeAcl { NodeAclId = "grant", ClusterId = "cluster", Principal = "peer", ScopeKind = NodeAclScopeKind.RawFolder,
|
||||
ScopeId = "folder", PermissionFlags = NodePermissions.ReadOnly }],
|
||||
ScopeId = "folder", PermissionFlags = writes is null ? NodePermissions.ReadOnly : NodePermissions.Operator }],
|
||||
new Dictionary<AclScopeRef, IReadOnlyList<NodeAclPath>> { [new(NodeAclScopeKind.RawFolder, "folder")] = [new(["raw", "Plant"])] });
|
||||
Serving = Serving with { AuthorityEpoch = Authority.Current.GenerationId };
|
||||
}
|
||||
@@ -153,6 +157,7 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
Activation.Complete(epoch, true);
|
||||
Context = new("peer", key.ApiKeyId, DataCallerIdentity.CredentialVersionFor(key), Clock.GetUtcNow().AddMinutes(10), Authority.Current.GenerationId);
|
||||
var operations = DataOperations.Browse | DataOperations.Metadata | DataOperations.Read | DataOperations.Write | DataOperations.Subscribe;
|
||||
if (denyReadExport) operations &= ~DataOperations.Read;
|
||||
var rootMetadata = new DataMetadata(Root, "Plant", "Folder", DataValueKind.Null, -1, [], false, operations, 1, null, null, false);
|
||||
var rawMetadata = new DataMetadata(Raw, "Speed", "Variable", DataValueKind.Int32, -1, [], true, operations, 1, Ticket.Key.StableSourceId, "rpm", false);
|
||||
var unsMetadata = rawMetadata with { View = Uns };
|
||||
@@ -186,11 +191,11 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
var limits = new DataLimits(100, 100, 1_000_000, 100, 10, 1_000_000, TimeSpan.FromSeconds(15), TimeSpan.FromHours(1), TimeSpan.FromMinutes(1));
|
||||
var capabilities = new DataCapabilitiesProvider("cluster", () => Serving, () => Catalog.IsActive, limits);
|
||||
Services = new LocalDataServices(() => Catalog, Hub, new DataOperationPolicy(Authority,
|
||||
new TriePermissionEvaluator(Authority.Tries, Clock), Clock), capabilities, Clock, subscriptions: subscriptions,
|
||||
new TriePermissionEvaluator(Authority.Tries, Clock), Clock), capabilities, Clock, writes: writes, subscriptions: subscriptions,
|
||||
targetSubscriptions: targetSubscriptions);
|
||||
}
|
||||
|
||||
internal IDataConnection Connection() => Services.Create(Context, new(DataTargetMode.Node, "cluster", "node-a"));
|
||||
internal IDataConnection Connection() => Services.Create(Context, new(DataTargetMode.Node, "cluster", Serving.NodeId));
|
||||
internal void Publish(int value, bool beforeActivation = false)
|
||||
{
|
||||
using var owned = DataValue.FromScalar(DataValueKind.Int32, value);
|
||||
|
||||
Reference in New Issue
Block a user