File tree Expand file tree Collapse file tree 2 files changed +3
-24
lines changed Expand file tree Collapse file tree 2 files changed +3
-24
lines changed Original file line number Diff line number Diff line change @@ -43,14 +43,10 @@ func New() *Unstructured {
4343}
4444
4545// To converts a unstructured composed resource to the provided object.
46- func To (un * Unstructured , obj interface {}) error {
47- rt , ok := obj .(runtime.Object )
48- if ! ok {
49- return errors .New ("object is not a compatible runtime.Object" )
50- }
46+ func To [T runtime.Object ](un * Unstructured , obj T ) error {
5147
5248 // Get known GVKs for the runtime object type
53- knownGVKs , _ , err := Scheme .ObjectKinds (rt )
49+ knownGVKs , _ , err := Scheme .ObjectKinds (obj )
5450 if err != nil {
5551 return errors .Errorf ("could not retrieve GVKs for the provided object: %v" , err )
5652 }
Original file line number Diff line number Diff line change @@ -241,7 +241,7 @@ func TestTo(t *testing.T) {
241241 v1beta1 .AddToScheme (Scheme )
242242 type args struct {
243243 un * Unstructured
244- obj interface {}
244+ obj runtime. Object
245245 }
246246 type want struct {
247247 obj interface {}
@@ -316,23 +316,6 @@ func TestTo(t *testing.T) {
316316 err : errors .New ("GVK /test.example.io, Kind=Unknown is not known by the scheme for the provided object type" ),
317317 },
318318 },
319- "NoRuntimeObject" : {
320- reason : "Should only convert to a object if the object is a runtime.Object" ,
321- args : args {
322- un : & Unstructured {Unstructured : unstructured.Unstructured {Object : map [string ]any {
323- "apiVersion" : v1beta1 .CRDGroupVersion .String (),
324- "kind" : v1beta1 .Bucket_Kind ,
325- "metadata" : map [string ]any {
326- "name" : "cool-bucket" ,
327- },
328- }}},
329- obj : "not-a-runtime-object" ,
330- },
331- want : want {
332- obj : string ("not-a-runtime-object" ),
333- err : errors .New ("object is not a compatible runtime.Object" ),
334- },
335- },
336319 }
337320
338321 for name , tc := range cases {
You can’t perform that action at this time.
0 commit comments