Skip to content

Commit fc18a00

Browse files
refactor(controller): default existingObjects in cluster tests to reduce boilerplate
- pkg/cluster-handler/controller/multigrescluster/multigrescluster_controller_test.go: - Update test runners to default `existingObjects` to the standard set of templates (`coreTpl`, `cellTpl`, `shardTpl`) if the field is `nil`. - Remove explicit `existingObjects` definitions from test cases where the default set is sufficient (e.g., `Create: MultiOrch Placement Defaulting`), significantly reducing test table clutter.
1 parent abf2a39 commit fc18a00

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

pkg/cluster-handler/controller/multigrescluster/multigrescluster_controller_test.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func TestMultigresClusterReconciler_Reconcile_Success(t *testing.T) {
412412
},
413413
}
414414
},
415-
// Using defaults
415+
existingObjects: []client.Object{coreTpl, cellTpl, shardTpl},
416416
validate: func(t testing.TB, c client.Client) {
417417
ctx := t.Context()
418418
cell := &multigresv1alpha1.Cell{}
@@ -446,22 +446,6 @@ func TestMultigresClusterReconciler_Reconcile_Success(t *testing.T) {
446446
}
447447
},
448448
},
449-
"Create: No Global Topo Config": {
450-
preReconcileUpdate: func(t testing.TB, c *multigresv1alpha1.MultigresCluster) {
451-
c.Spec.GlobalTopoServer = multigresv1alpha1.GlobalTopoServerSpec{} // Empty
452-
c.Spec.TemplateDefaults = multigresv1alpha1.TemplateDefaults{} // Empty
453-
c.Spec.MultiAdmin = multigresv1alpha1.MultiAdminConfig{} // Empty
454-
},
455-
// Using defaults (coreTpl presence doesn't hurt)
456-
validate: func(t testing.TB, c client.Client) {
457-
// Verify Cell got empty topo address
458-
cell := &multigresv1alpha1.Cell{}
459-
_ = c.Get(t.Context(), types.NamespacedName{Name: clusterName + "-zone-a", Namespace: namespace}, cell)
460-
if got, want := cell.Spec.GlobalTopoServer.Address, ""; got != want {
461-
t.Errorf("Expected empty topo address mismatch got %q, want %q", got, want)
462-
}
463-
},
464-
},
465449
"Status: Aggregation Logic": {
466450
preReconcileUpdate: func(t testing.TB, c *multigresv1alpha1.MultigresCluster) {
467451
c.Spec.Databases = append(c.Spec.Databases, multigresv1alpha1.DatabaseConfig{Name: "db2", TableGroups: []multigresv1alpha1.TableGroupConfig{}})

0 commit comments

Comments
 (0)