@@ -445,18 +445,26 @@ func (i *InfrastructureMachineTemplateBuilder) Build() *unstructured.Unstructure
445
445
}
446
446
447
447
// TestInfrastructureMachineTemplateBuilder holds the variables and objects needed to build an TestInfrastructureMachineTemplate.
448
- // +kubebuilder:object:generate=false
449
448
type TestInfrastructureMachineTemplateBuilder struct {
450
- namespace string
451
- name string
452
- specFields map [string ]interface {}
449
+ obj * unstructured.Unstructured
453
450
}
454
451
455
452
// TestInfrastructureMachineTemplate creates an TestInfrastructureMachineTemplateBuilder with the given name and namespace.
456
453
func TestInfrastructureMachineTemplate (namespace , name string ) * TestInfrastructureMachineTemplateBuilder {
454
+ obj := & unstructured.Unstructured {}
455
+ obj .SetName (name )
456
+ obj .SetNamespace (namespace )
457
+ obj .SetAPIVersion (InfrastructureGroupVersion .String ())
458
+ obj .SetKind (TestInfrastructureMachineTemplateKind )
459
+ // Set the mandatory spec fields for the object.
460
+ if err := unstructured .SetNestedField (obj .Object , map [string ]interface {}{}, "spec" ); err != nil {
461
+ panic (err )
462
+ }
463
+ if err := unstructured .SetNestedField (obj .Object , map [string ]interface {}{}, "spec" , "template" , "spec" ); err != nil {
464
+ panic (err )
465
+ }
457
466
return & TestInfrastructureMachineTemplateBuilder {
458
- namespace : namespace ,
459
- name : name ,
467
+ obj ,
460
468
}
461
469
}
462
470
@@ -469,24 +477,13 @@ func TestInfrastructureMachineTemplate(namespace, name string) *TestInfrastructu
469
477
// "spec.version": "v1.2.3",
470
478
// }.
471
479
func (i * TestInfrastructureMachineTemplateBuilder ) WithSpecFields (fields map [string ]interface {}) * TestInfrastructureMachineTemplateBuilder {
472
- i . specFields = fields
480
+ setSpecFields ( i . obj , fields )
473
481
return i
474
482
}
475
483
476
484
// Build takes the objects and variables in the InfrastructureMachineTemplateBuilder and generates an unstructured object.
477
485
func (i * TestInfrastructureMachineTemplateBuilder ) Build () * unstructured.Unstructured {
478
- obj := & unstructured.Unstructured {}
479
- obj .SetAPIVersion (InfrastructureGroupVersion .String ())
480
- obj .SetKind (TestInfrastructureMachineTemplateKind )
481
- obj .SetNamespace (i .namespace )
482
- obj .SetName (i .name )
483
-
484
- // Initialize the spec.template.spec to make the object valid in reconciliation.
485
- setSpecFields (obj , map [string ]interface {}{"spec.template.spec" : map [string ]interface {}{}})
486
-
487
- setSpecFields (obj , i .specFields )
488
-
489
- return obj
486
+ return i .obj
490
487
}
491
488
492
489
// BootstrapTemplateBuilder holds the variables needed to build a generic BootstrapTemplate.
0 commit comments