Files
git.stella-ops.org/src/Graph/__Tests/StellaOps.Graph.Indexer.Tests/GraphIdentityTests.cs
master 10212d67c0
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
api-governance / spectral-lint (push) Has been cancelled
Refactor code structure for improved readability and maintainability; removed redundant code blocks and optimized function calls.
2025-11-20 07:50:52 +02:00

47 lines
1.6 KiB
C#

using System.Collections.Immutable;
using StellaOps.Graph.Indexer.Schema;
namespace StellaOps.Graph.Indexer.Tests;
public sealed class GraphIdentityTests
{
[Fact]
public void ComputeNodeId_IsDeterministic_WhenTupleOrderChanges()
{
var tupleA = ImmutableDictionary<string, string>.Empty
.Add("purl", "pkg:npm/test@1.0.0")
.Add("reason", "declared")
.Add("scope", "runtime");
var tupleB = ImmutableDictionary<string, string>.Empty
.Add("scope", "runtime")
.Add("reason", "declared")
.Add("purl", "pkg:npm/test@1.0.0");
var idA = GraphIdentity.ComputeNodeId("Tenant-A", "Component", tupleA);
var idB = GraphIdentity.ComputeNodeId("tenant-a", "component", tupleB);
Assert.Equal(idA, idB);
Assert.StartsWith("gn:tenant-a:component:", idA);
}
[Fact]
public void ComputeEdgeId_IsCaseInsensitiveExceptFingerprintFields()
{
var tupleLower = ImmutableDictionary<string, string>.Empty
.Add("digest", "sha256:ABC")
.Add("source", "sbom");
var tupleUpper = ImmutableDictionary<string, string>.Empty
.Add("digest", "sha256:abc")
.Add("source", "SBOM");
var edgeA = GraphIdentity.ComputeEdgeId("TENANT", "depends_on", tupleLower);
var edgeB = GraphIdentity.ComputeEdgeId("tenant", "DEPENDS_ON", tupleUpper);
// digest key is case-sensitive by design; different casing produces different id when value changes.
Assert.NotEqual(edgeA, edgeB);
Assert.StartsWith("ge:tenant:DEPENDS_ON:", edgeA);
}
}