mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 21:53:52 +00:00
Merge pull request #128274 from eddycharly/fix-cel-type-provider
fix: cel type provider should return a type type
This commit is contained in:
@@ -429,7 +429,7 @@ func (rt *DeclTypeProvider) FindStructType(typeName string) (*types.Type, bool)
|
|||||||
declType, found := rt.findDeclType(typeName)
|
declType, found := rt.findDeclType(typeName)
|
||||||
if found {
|
if found {
|
||||||
expT := declType.CelType()
|
expT := declType.CelType()
|
||||||
return expT, found
|
return types.NewTypeTypeWithParam(expT), found
|
||||||
}
|
}
|
||||||
return rt.typeProvider.FindStructType(typeName)
|
return rt.typeProvider.FindStructType(typeName)
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,9 @@ package cel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/cel-go/common/types"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTypes_ListType(t *testing.T) {
|
func TestTypes_ListType(t *testing.T) {
|
||||||
@@ -77,3 +80,16 @@ func testValue(t *testing.T, id int64, val interface{}) *DynValue {
|
|||||||
}
|
}
|
||||||
return dv
|
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())
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user