mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +00:00
Handle nil values in conversion.EnforcePtr()
Signed-off-by: Vojtech Vitek (V-Teq) <vvitek@redhat.com>
This commit is contained in:
parent
6a6f24b126
commit
8969f0df7e
@ -118,5 +118,8 @@ func EnforcePtr(obj interface{}) (reflect.Value, error) {
|
|||||||
}
|
}
|
||||||
return reflect.Value{}, fmt.Errorf("expected pointer, but got %v type", v.Type().Name())
|
return reflect.Value{}, fmt.Errorf("expected pointer, but got %v type", v.Type().Name())
|
||||||
}
|
}
|
||||||
|
if v.IsNil() {
|
||||||
|
return reflect.Value{}, fmt.Errorf("expected pointer, but got nil")
|
||||||
|
}
|
||||||
return v.Elem(), nil
|
return v.Elem(), nil
|
||||||
}
|
}
|
||||||
|
@ -253,3 +253,11 @@ func TestInvalidPtrValueKind(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEnforceNilPtr(t *testing.T) {
|
||||||
|
var nilPtr *struct{}
|
||||||
|
_, err := EnforcePtr(nilPtr)
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Expected error on nil pointer")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user