From 2193c79724f56943237bf94dda7e0cbb40b9ddfd Mon Sep 17 00:00:00 2001 From: Adrian Tam Date: Thu, 8 Jan 2026 11:59:19 -0500 Subject: [PATCH] test: add test to assert empty intersection invalid Add unit test to assert that empty intersection / empty union model are marked as invalid. --- pkg/go/graph/weighted_graph_builder_test.go | 63 +++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/pkg/go/graph/weighted_graph_builder_test.go b/pkg/go/graph/weighted_graph_builder_test.go index 5136d493..ccbf4cdb 100644 --- a/pkg/go/graph/weighted_graph_builder_test.go +++ b/pkg/go/graph/weighted_graph_builder_test.go @@ -3,6 +3,7 @@ package graph import ( "testing" + openfgav1 "github.com/openfga/api/proto/openfga/v1" "github.com/stretchr/testify/require" language "github.com/openfga/language/pkg/go/transformer" @@ -1935,6 +1936,68 @@ func TestGraphConstructionIntersection(t *testing.T) { _, err := wgb.Build(authorizationModel) require.ErrorContains(t, err, "invalid model: not all paths return the same type for the node intersection:") }) + t.Run("empty_intersection", func(t *testing.T) { + t.Parallel() + authorizationModel := &openfgav1.AuthorizationModel{ + SchemaVersion: "1.1", + TypeDefinitions: []*openfgav1.TypeDefinition{ + { + Type: "user", + }, + { + Type: "document", + Relations: map[string]*openfgav1.Userset{ + "viewer": { + Userset: &openfgav1.Userset_Intersection{ + Intersection: &openfgav1.Usersets{ + Child: []*openfgav1.Userset{}, + }, + }, + }, + }, + Metadata: &openfgav1.Metadata{ + Relations: map[string]*openfgav1.RelationMetadata{ + "viewer": {}, + }, + }, + }, + }, + } + wgb := NewWeightedAuthorizationModelGraphBuilder() + _, err := wgb.Build(authorizationModel) + require.Error(t, err) + }) + t.Run("empty_union", func(t *testing.T) { + t.Parallel() + authorizationModel := &openfgav1.AuthorizationModel{ + SchemaVersion: "1.1", + TypeDefinitions: []*openfgav1.TypeDefinition{ + { + Type: "user", + }, + { + Type: "document", + Relations: map[string]*openfgav1.Userset{ + "viewer": { + Userset: &openfgav1.Userset_Union{ + Union: &openfgav1.Usersets{ + Child: []*openfgav1.Userset{}, + }, + }, + }, + }, + Metadata: &openfgav1.Metadata{ + Relations: map[string]*openfgav1.RelationMetadata{ + "viewer": {}, + }, + }, + }, + }, + } + wgb := NewWeightedAuthorizationModelGraphBuilder() + _, err := wgb.Build(authorizationModel) + require.Error(t, err) + }) }) t.Run("multiple_intersections", func(t *testing.T) {