Commit ae3f10a3 authored by Michal Fojtik's avatar Michal Fojtik

Ensure the ptr is pointing to reflect.Slice in ExtractList

parent 60eba74c
...@@ -43,6 +43,10 @@ func GetItemsPtr(list Object) (interface{}, error) { ...@@ -43,6 +43,10 @@ func GetItemsPtr(list Object) (interface{}, error) {
} }
switch items.Kind() { switch items.Kind() {
case reflect.Interface, reflect.Ptr: case reflect.Interface, reflect.Ptr:
target := reflect.TypeOf(items.Interface()).Elem()
if target.Kind() != reflect.Slice {
return nil, fmt.Errorf("items: Expected slice, got %s", target.Kind())
}
return items.Interface(), nil return items.Interface(), nil
case reflect.Slice: case reflect.Slice:
return items.Addr().Interface(), nil return items.Addr().Interface(), nil
......
...@@ -86,14 +86,14 @@ func TestExtractListGeneric(t *testing.T) { ...@@ -86,14 +86,14 @@ func TestExtractListGeneric(t *testing.T) {
} }
type fakePtrInterfaceList struct { type fakePtrInterfaceList struct {
Items []*runtime.Object Items *[]runtime.Object
} }
func (f fakePtrInterfaceList) IsAnAPIObject() {} func (f fakePtrInterfaceList) IsAnAPIObject() {}
func TestExtractListOfInterfacePtrs(t *testing.T) { func TestExtractListOfInterfacePtrs(t *testing.T) {
pl := &fakePtrInterfaceList{ pl := &fakePtrInterfaceList{
Items: []*runtime.Object{}, Items: &[]runtime.Object{},
} }
list, err := runtime.ExtractList(pl) list, err := runtime.ExtractList(pl)
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment