@@ -137,7 +137,6 @@ func TestMultigresClusterReconciler_Reconcile_Success(t *testing.T) {
137137 multigrescluster * multigresv1alpha1.MultigresCluster
138138 existingObjects []client.Object
139139 preReconcileUpdate func (testing.TB , * multigresv1alpha1.MultigresCluster )
140- setupFunc func (testing.TB , client.Client )
141140 validate func (testing.TB , client.Client )
142141 }{
143142 "Create: Adds Finalizer" : {
@@ -183,12 +182,13 @@ func TestMultigresClusterReconciler_Reconcile_Success(t *testing.T) {
183182 },
184183 },
185184 "Create: Independent Templates (Topo vs Admin)" : {
186- multigrescluster : baseCluster . DeepCopy (),
187- preReconcileUpdate : func ( t testing. TB , c * multigresv1alpha1. MultigresCluster ) {
185+ multigrescluster : func () * multigresv1alpha1. MultigresCluster {
186+ c := baseCluster . DeepCopy ()
188187 c .Spec .TemplateDefaults .CoreTemplate = "" // clear default
189188 c .Spec .GlobalTopoServer .TemplateRef = "topo-core"
190189 c .Spec .MultiAdmin .TemplateRef = "admin-core"
191- },
190+ return c
191+ }(),
192192 existingObjects : []client.Object {
193193 cellTpl , shardTpl ,
194194 & multigresv1alpha1.CoreTemplate {
@@ -478,20 +478,15 @@ func TestMultigresClusterReconciler_Reconcile_Success(t *testing.T) {
478478 preReconcileUpdate : func (t testing.TB , c * multigresv1alpha1.MultigresCluster ) {
479479 c .Spec .Databases = append (c .Spec .Databases , multigresv1alpha1.DatabaseConfig {Name : "db2" , TableGroups : []multigresv1alpha1.TableGroupConfig {}})
480480 },
481- existingObjects : []client.Object {coreTpl , cellTpl , shardTpl },
482- setupFunc : func (t testing.TB , c client.Client ) {
483- ctx := t .Context ()
484- cell := & multigresv1alpha1.Cell {
481+ existingObjects : []client.Object {
482+ coreTpl , cellTpl , shardTpl ,
483+ & multigresv1alpha1.Cell {
485484 ObjectMeta : metav1.ObjectMeta {Name : clusterName + "-zone-a" , Namespace : namespace , Labels : map [string ]string {"multigres.com/cluster" : clusterName }},
486485 Spec : multigresv1alpha1.CellSpec {Name : "zone-a" },
487- }
488- if err := c .Create (ctx , cell ); err != nil {
489- t .Fatalf ("failed to create cell: %v" , err )
490- }
491- cell .Status .Conditions = []metav1.Condition {{Type : "Available" , Status : metav1 .ConditionTrue }}
492- if err := c .Status ().Update (ctx , cell ); err != nil {
493- t .Fatalf ("failed to update cell status: %v" , err )
494- }
486+ Status : multigresv1alpha1.CellStatus {
487+ Conditions : []metav1.Condition {{Type : "Available" , Status : metav1 .ConditionTrue }},
488+ },
489+ },
495490 },
496491 validate : func (t testing.TB , c client.Client ) {
497492 cluster := & multigresv1alpha1.MultigresCluster {}
@@ -546,14 +541,8 @@ func TestMultigresClusterReconciler_Reconcile_Success(t *testing.T) {
546541 baseClient := clientBuilder .Build ()
547542
548543 var finalClient client.Client
549- // Use failureConfig only if it were in the struct, but this is Success suite.
550- // Success suite implies no failures injected.
551544 finalClient = baseClient
552545
553- if tc .setupFunc != nil {
554- tc .setupFunc (t , baseClient )
555- }
556-
557546 // Apply pre-reconcile updates if defined
558547 if tc .preReconcileUpdate != nil {
559548 tc .preReconcileUpdate (t , tc .multigrescluster )
@@ -610,7 +599,6 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
610599 existingObjects []client.Object
611600 failureConfig * testutil.FailureConfig
612601 preReconcileUpdate func (testing.TB , * multigresv1alpha1.MultigresCluster )
613- setupFunc func (testing.TB , client.Client )
614602 validate func (testing.TB , client.Client )
615603 }{
616604 "Delete: Block Finalization if Cells Exist" : {
@@ -851,7 +839,10 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
851839 failureConfig : & testutil.FailureConfig {OnCreate : testutil .FailOnObjectName (clusterName + "-zone-a" , errBoom )},
852840 },
853841 "Error: Prune Cell Failed" : {
854- multigrescluster : baseCluster .DeepCopy (),
842+ multigrescluster : func () * multigresv1alpha1.MultigresCluster {
843+ c := baseCluster .DeepCopy ()
844+ return c
845+ }(),
855846 existingObjects : []client.Object {
856847 coreTpl , cellTpl , shardTpl ,
857848 & multigresv1alpha1.Cell {ObjectMeta : metav1.ObjectMeta {Name : clusterName + "-zone-b" , Namespace : namespace , Labels : map [string ]string {"multigres.com/cluster" : clusterName }}},
@@ -881,7 +872,10 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
881872 failureConfig : & testutil.FailureConfig {OnCreate : testutil .FailOnObjectName (clusterName + "-db1-tg1" , errBoom )},
882873 },
883874 "Error: Prune TableGroup Failed" : {
884- multigrescluster : baseCluster .DeepCopy (),
875+ multigrescluster : func () * multigresv1alpha1.MultigresCluster {
876+ c := baseCluster .DeepCopy ()
877+ return c
878+ }(),
885879 existingObjects : []client.Object {
886880 coreTpl , cellTpl , shardTpl ,
887881 & multigresv1alpha1.TableGroup {ObjectMeta : metav1.ObjectMeta {Name : clusterName + "-orphan-tg" , Namespace : namespace , Labels : map [string ]string {"multigres.com/cluster" : clusterName }}},
@@ -1022,10 +1016,6 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
10221016 finalClient = baseClient
10231017 }
10241018
1025- if tc .setupFunc != nil {
1026- tc .setupFunc (t , baseClient )
1027- }
1028-
10291019 // Apply pre-reconcile updates if defined
10301020 if tc .preReconcileUpdate != nil {
10311021 tc .preReconcileUpdate (t , tc .multigrescluster )
0 commit comments