test(otopcua): ConfigComposer->ParseComposition DeviceHost round-trip (follow-up E)
This commit is contained in:
@@ -4,6 +4,7 @@ using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
||||
using ZB.MOM.WW.OtOpcUa.ControlPlane.AdminOperations;
|
||||
using ZB.MOM.WW.OtOpcUa.ControlPlane.Tests.Harness;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.Drivers;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.ControlPlane.Tests;
|
||||
|
||||
@@ -85,6 +86,58 @@ public sealed class ConfigComposerTests : ControlPlaneActorTestBase
|
||||
artifact.RevisionHash.ShouldMatch("^[0-9a-f]{64}$");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="ConfigComposer.SnapshotAndFlattenAsync"/> serialises a
|
||||
/// <see cref="Device"/>'s <c>HostAddress</c> into the artifact blob and that
|
||||
/// <see cref="DeploymentArtifact.ParseComposition(ReadOnlySpan{byte})"/> decodes it back
|
||||
/// as the equipment's <see cref="ZB.MOM.WW.OtOpcUa.OpcUaServer.EquipmentNode.DeviceHost"/>
|
||||
/// (follow-up E). Guards the real serialize→decode seam: if ConfigComposer's Device
|
||||
/// serialisation ever drifted, DeviceHost would silently become null in production
|
||||
/// (feature E degrades to a warn-skip) while hand-rolled artifact tests stayed green.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DeviceHost_survives_ConfigComposer_to_ParseComposition_round_trip()
|
||||
{
|
||||
var f = NewInMemoryDbFactory();
|
||||
await using (var db = f.CreateDbContext())
|
||||
{
|
||||
db.ServerClusters.Add(NewCluster("c1"));
|
||||
db.Namespaces.Add(new Namespace
|
||||
{
|
||||
NamespaceId = "ns-eq", ClusterId = "c1",
|
||||
Kind = NamespaceKind.Equipment, NamespaceUri = "urn:eq",
|
||||
});
|
||||
db.DriverInstances.Add(new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "drv-1", ClusterId = "c1", NamespaceId = "ns-eq",
|
||||
Name = "Focas", DriverType = "Focas", DriverConfig = "{}",
|
||||
});
|
||||
db.Devices.Add(new Device
|
||||
{
|
||||
DeviceId = "dev-1", DriverInstanceId = "drv-1",
|
||||
Name = "dev-1", DeviceConfig = "{\"HostAddress\":\"10.9.9.9:8193\"}",
|
||||
});
|
||||
db.UnsAreas.Add(new UnsArea { UnsAreaId = "area-1", ClusterId = "c1", Name = "area-1" });
|
||||
db.UnsLines.Add(new UnsLine { UnsLineId = "line-1", UnsAreaId = "area-1", Name = "line-1" });
|
||||
db.Equipment.Add(new Equipment
|
||||
{
|
||||
EquipmentId = "eq-1", DriverInstanceId = "drv-1", DeviceId = "dev-1",
|
||||
UnsLineId = "line-1", Name = "machine-1", MachineCode = "MACHINE_001",
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await using var readDb = f.CreateDbContext();
|
||||
var artifact = await ConfigComposer.SnapshotAndFlattenAsync(readDb);
|
||||
var composition = DeploymentArtifact.ParseComposition(artifact.Blob);
|
||||
|
||||
var node = composition.EquipmentNodes.ShouldHaveSingleItem();
|
||||
node.EquipmentId.ShouldBe("eq-1");
|
||||
node.DriverInstanceId.ShouldBe("drv-1");
|
||||
node.DeviceId.ShouldBe("dev-1");
|
||||
node.DeviceHost.ShouldBe("10.9.9.9:8193");
|
||||
}
|
||||
|
||||
private static readonly DateTime FixedTimestamp = new(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
private static ServerCluster NewCluster(string id) => new()
|
||||
|
||||
Reference in New Issue
Block a user