@@ -445,18 +445,26 @@ func (i *InfrastructureMachineTemplateBuilder) Build() *unstructured.Unstructure
445445}
446446
447447// TestInfrastructureMachineTemplateBuilder holds the variables and objects needed to build an TestInfrastructureMachineTemplate.
448- // +kubebuilder:object:generate=false
449448type TestInfrastructureMachineTemplateBuilder struct {
450- namespace string
451- name string
452- specFields map [string ]interface {}
449+ obj * unstructured.Unstructured
453450}
454451
455452// TestInfrastructureMachineTemplate creates an TestInfrastructureMachineTemplateBuilder with the given name and namespace.
456453func 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+ }
457466 return & TestInfrastructureMachineTemplateBuilder {
458- namespace : namespace ,
459- name : name ,
467+ obj ,
460468 }
461469}
462470
@@ -469,24 +477,13 @@ func TestInfrastructureMachineTemplate(namespace, name string) *TestInfrastructu
469477// "spec.version": "v1.2.3",
470478// }.
471479func (i * TestInfrastructureMachineTemplateBuilder ) WithSpecFields (fields map [string ]interface {}) * TestInfrastructureMachineTemplateBuilder {
472- i . specFields = fields
480+ setSpecFields ( i . obj , fields )
473481 return i
474482}
475483
476484// Build takes the objects and variables in the InfrastructureMachineTemplateBuilder and generates an unstructured object.
477485func (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
490487}
491488
492489// BootstrapTemplateBuilder holds the variables needed to build a generic BootstrapTemplate.
0 commit comments