mirror of https://github.com/k3s-io/k3s
Merge pull request #3836 from mfojtik/extract_list_ptr
Ensure the ptr is pointing to reflect.Slice in ExtractListpull/6/head
commit
99b9785881
|
@ -43,6 +43,10 @@ func GetItemsPtr(list Object) (interface{}, error) {
|
|||
}
|
||||
switch items.Kind() {
|
||||
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
|
||||
case reflect.Slice:
|
||||
return items.Addr().Interface(), nil
|
||||
|
|
|
@ -86,14 +86,14 @@ func TestExtractListGeneric(t *testing.T) {
|
|||
}
|
||||
|
||||
type fakePtrInterfaceList struct {
|
||||
Items []*runtime.Object
|
||||
Items *[]runtime.Object
|
||||
}
|
||||
|
||||
func (f fakePtrInterfaceList) IsAnAPIObject() {}
|
||||
|
||||
func TestExtractListOfInterfacePtrs(t *testing.T) {
|
||||
pl := &fakePtrInterfaceList{
|
||||
Items: []*runtime.Object{},
|
||||
Items: &[]runtime.Object{},
|
||||
}
|
||||
list, err := runtime.ExtractList(pl)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue