Skip to content

Commit e483c8c

Browse files
authored
Merge pull request #835 from jakobmoellerdev/test-nested-struct-on-map
test: nested object types assign
2 parents 34ac760 + e4e6fea commit e483c8c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkg/cel/compatibility_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,15 @@ func TestMapToStructCompatibility(t *testing.T) {
453453
}
454454
stringStruct := apiservercel.NewObjectType(TypeNamePrefix+"stringStruct", stringStructFields)
455455

456-
provider := NewDeclTypeProvider(intStruct, stringStruct)
456+
nestedObjectType := apiservercel.NewObjectType(TypeNamePrefix+"nestedObject", map[string]*apiservercel.DeclField{
457+
"int": apiservercel.NewDeclField("int", apiservercel.IntType, true, nil, nil),
458+
})
459+
parentObjectType := apiservercel.NewObjectType(TypeNamePrefix+"parentObject", map[string]*apiservercel.DeclField{
460+
"string": apiservercel.NewDeclField("string", apiservercel.StringType, true, nil, nil),
461+
"nested": apiservercel.NewDeclField("nested", nestedObjectType, false, nil, nil),
462+
})
463+
464+
provider := NewDeclTypeProvider(intStruct, stringStruct, parentObjectType, nestedObjectType)
457465

458466
tests := []struct {
459467
name string
@@ -500,6 +508,12 @@ func TestMapToStructCompatibility(t *testing.T) {
500508
compatible: false,
501509
errContains: "incompatible",
502510
},
511+
{
512+
name: "map[string]dyn → struct{x:string, y: struct{x: int}} OK",
513+
output: cel.MapType(cel.StringType, cel.DynType),
514+
expected: parentObjectType.CelType(),
515+
compatible: true,
516+
},
503517
}
504518

505519
for _, tt := range tests {

0 commit comments

Comments
 (0)