@@ -18,7 +18,6 @@ package baremetal
1818
1919import (
2020 "context"
21- "strconv"
2221
2322 "github.com/go-logr/logr"
2423 infrav1 "github.com/metal3-io/cluster-api-provider-metal3/api/v1beta1"
@@ -427,173 +426,6 @@ var _ = Describe("Metal3DataTemplate manager", func() {
427426 }),
428427 )
429428
430- type testCaseTemplateReference struct {
431- template1 * infrav1.Metal3DataTemplate
432- template2 * infrav1.Metal3DataTemplate
433- dataObject * infrav1.Metal3Data
434- dataClaim * infrav1.Metal3DataClaim
435- indexes map [int ]string
436- expectError bool
437- expectTemplateReference bool
438- expectDataObjectAssociated bool
439- }
440-
441- DescribeTable ("Test Template Reference" ,
442- func (tc testCaseTemplateReference ) {
443- objects := []client.Object {}
444- objects = append (objects , tc .dataClaim )
445- if tc .dataObject != nil {
446- objects = append (objects , tc .dataObject )
447- }
448- fakeClient := fake .NewClientBuilder ().WithScheme (setupSchemeMm ()).WithObjects (objects ... ).Build ()
449- templateMgr , err := NewDataTemplateManager (fakeClient , tc .template2 ,
450- logr .Discard (),
451- )
452- Expect (err ).NotTo (HaveOccurred ())
453-
454- _ , err = templateMgr .createData (context .TODO (), tc .dataClaim , tc .indexes )
455- if tc .expectError {
456- Expect (err ).To (HaveOccurred ())
457- } else {
458- Expect (err ).NotTo (HaveOccurred ())
459- }
460-
461- dataObjects := infrav1.Metal3DataList {}
462- opts := & client.ListOptions {}
463- err = fakeClient .List (context .TODO (), & dataObjects , opts )
464- Expect (err ).NotTo (HaveOccurred ())
465- if tc .dataObject != nil {
466- Expect (dataObjects .Items ).To (HaveLen (2 ))
467- } else {
468- Expect (dataObjects .Items ).To (HaveLen (1 ))
469- }
470-
471- if tc .expectTemplateReference {
472- Expect (dataObjects .Items [0 ].Spec .TemplateReference ).To (Equal (tc .template1 .Name ))
473- } else {
474- Expect (dataObjects .Items [0 ].Spec .TemplateReference ).ToNot (Equal (tc .template1 .Name ))
475- }
476-
477- if tc .dataObject != nil {
478- if tc .expectDataObjectAssociated {
479- result := templateMgr .dataObjectBelongsToTemplate (* tc .dataObject )
480- Expect (result ).To (BeTrue ())
481- dataClaimIndex := tc .template1 .Status .Indexes [tc .dataClaim .ObjectMeta .Name ]
482- Expect (tc .dataObject .ObjectMeta .Name ).To (Equal (
483- tc .template1 .ObjectMeta .Name + "-" + strconv .Itoa (dataClaimIndex )))
484- } else {
485- result := templateMgr .dataObjectBelongsToTemplate (* tc .dataObject )
486- Expect (result ).To (BeFalse ())
487- dataClaimIndex := tc .template1 .Status .Indexes [tc .dataClaim .ObjectMeta .Name ]
488- Expect (tc .dataObject .ObjectMeta .Name ).ToNot (Equal (tc .template1 .ObjectMeta .Name + "-" + strconv .Itoa (dataClaimIndex )))
489- }
490- }
491- },
492- Entry ("TemplateReferenceExist" , testCaseTemplateReference {
493- template1 : & infrav1.Metal3DataTemplate {
494- ObjectMeta : templateMeta ,
495- Spec : infrav1.Metal3DataTemplateSpec {},
496- },
497- indexes : map [int ]string {},
498- template2 : & infrav1.Metal3DataTemplate {
499- ObjectMeta : testObjectMeta ("abc1" , namespaceName , "" ),
500- Spec : infrav1.Metal3DataTemplateSpec {
501- TemplateReference : "abc" ,
502- },
503- Status : infrav1.Metal3DataTemplateStatus {
504- Indexes : map [string ]int {},
505- },
506- },
507- dataClaim : & infrav1.Metal3DataClaim {
508- ObjectMeta : testObjectMetaWithOR (metal3DataClaimName , metal3machineName ),
509- },
510- expectTemplateReference : true ,
511- }),
512- Entry ("TemplateReferenceDoNotExist" , testCaseTemplateReference {
513- template1 : & infrav1.Metal3DataTemplate {
514- ObjectMeta : templateMeta ,
515- Spec : infrav1.Metal3DataTemplateSpec {},
516- },
517- indexes : map [int ]string {},
518- template2 : & infrav1.Metal3DataTemplate {
519- ObjectMeta : testObjectMeta ("abc1" , namespaceName , "" ),
520- Spec : infrav1.Metal3DataTemplateSpec {},
521- Status : infrav1.Metal3DataTemplateStatus {
522- Indexes : map [string ]int {},
523- },
524- },
525- dataClaim : & infrav1.Metal3DataClaim {
526- ObjectMeta : testObjectMetaWithOR (metal3DataClaimName , metal3machineName ),
527- },
528- expectTemplateReference : false ,
529- }),
530- Entry ("TemplateReferenceRefersToOldTemplate" , testCaseTemplateReference {
531- template1 : & infrav1.Metal3DataTemplate {
532- ObjectMeta : metav1.ObjectMeta {
533- Name : "template1" ,
534- Namespace : namespaceName ,
535- },
536- Spec : infrav1.Metal3DataTemplateSpec {},
537- },
538- indexes : map [int ]string {},
539- template2 : & infrav1.Metal3DataTemplate {
540- ObjectMeta : metav1.ObjectMeta {
541- Name : "template2" ,
542- Namespace : namespaceName ,
543- },
544- Spec : infrav1.Metal3DataTemplateSpec {
545- TemplateReference : "template1" ,
546- },
547- Status : infrav1.Metal3DataTemplateStatus {
548- Indexes : map [string ]int {},
549- },
550- },
551- dataClaim : & infrav1.Metal3DataClaim {
552- ObjectMeta : testObjectMetaWithOR (metal3DataClaimName , metal3machineName ),
553- },
554- expectTemplateReference : true ,
555- expectDataObjectAssociated : true ,
556- }),
557- Entry ("TemplateReferenceRefersToZombieTemplate" , testCaseTemplateReference {
558- template1 : & infrav1.Metal3DataTemplate {
559- ObjectMeta : metav1.ObjectMeta {
560- Name : "template1" ,
561- Namespace : namespaceName ,
562- },
563- Spec : infrav1.Metal3DataTemplateSpec {},
564- },
565- indexes : map [int ]string {},
566- template2 : & infrav1.Metal3DataTemplate {
567- ObjectMeta : metav1.ObjectMeta {
568- Name : "template2" ,
569- Namespace : namespaceName ,
570- },
571- Spec : infrav1.Metal3DataTemplateSpec {
572- TemplateReference : "template1" ,
573- },
574- Status : infrav1.Metal3DataTemplateStatus {
575- Indexes : map [string ]int {},
576- },
577- },
578- dataClaim : & infrav1.Metal3DataClaim {
579- ObjectMeta : testObjectMetaWithOR (metal3DataClaimName , metal3machineName ),
580- },
581- dataObject : & infrav1.Metal3Data {
582- ObjectMeta : testObjectMeta (metal3DataName , namespaceName , "" ),
583- Spec : infrav1.Metal3DataSpec {
584- Index : 0 ,
585- Template : corev1.ObjectReference {
586- Name : "template12" ,
587- },
588- Claim : corev1.ObjectReference {
589- Name : "abc" ,
590- },
591- },
592- },
593- expectDataObjectAssociated : false ,
594- }),
595- )
596-
597429 type testCaseCreateAddresses struct {
598430 template * infrav1.Metal3DataTemplate
599431 dataClaim * infrav1.Metal3DataClaim
0 commit comments