Merge pull request #128274 from eddycharly/fix-cel-type-provider

fix: cel type provider should return a type type
This commit is contained in:
Kubernetes Prow Robot
2024-10-30 00:17:30 +00:00
committed by GitHub
2 changed files with 17 additions and 1 deletions

View File

@@ -429,7 +429,7 @@ func (rt *DeclTypeProvider) FindStructType(typeName string) (*types.Type, bool)
declType, found := rt.findDeclType(typeName)
if found {
expT := declType.CelType()
return expT, found
return types.NewTypeTypeWithParam(expT), found
}
return rt.typeProvider.FindStructType(typeName)
}

View File

@@ -18,6 +18,9 @@ package cel
import (
"testing"
"github.com/google/cel-go/common/types"
"github.com/stretchr/testify/require"
)
func TestTypes_ListType(t *testing.T) {
@@ -77,3 +80,16 @@ func testValue(t *testing.T, id int64, val interface{}) *DynValue {
}
return dv
}
func TestDeclTypeProvider_FindStructType(t *testing.T) {
obj := NewObjectType("foo", map[string]*DeclField{
"bar": NewDeclField("bar", StringType, true, nil, nil),
})
base := types.NewEmptyRegistry()
provider := NewDeclTypeProvider(obj)
provider, err := provider.WithTypeProvider(base)
require.NoError(t, err)
wrappedType, found := provider.FindStructType("foo")
require.True(t, found)
require.Equal(t, types.TypeKind, wrappedType.Kind())
}