Skip to content

Commit e69a2ce

Browse files
test: verify Cell wiring in MultigresCluster controller
Updates the `Create: Full Cluster Creation with Templates` and `Create: Independent Templates (Topo vs Admin)` test cases in `multigrescluster_controller_test.go` to assert that child `Cell` resources are created with the correct `GlobalTopoServer.Address`. This regression test ensures that the `getGlobalTopoRef` logic correctly resolves the Global TopoServer address from templates, preventing a previous issue where it would default to an empty string if no inline spec was provided.
1 parent 035bc79 commit e69a2ce

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,24 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
157157
validate: func(t *testing.T, c client.Client) {
158158
ctx := context.Background()
159159
updatedCluster := &multigresv1alpha1.MultigresCluster{}
160-
_ = c.Get(ctx, types.NamespacedName{Name: clusterName, Namespace: namespace}, updatedCluster)
160+
if err := c.Get(ctx, types.NamespacedName{Name: clusterName, Namespace: namespace}, updatedCluster); err != nil {
161+
t.Fatal(err)
162+
}
161163
if !controllerutil.ContainsFinalizer(updatedCluster, finalizerName) {
162164
t.Error("Finalizer was not added to Cluster")
163165
}
166+
167+
// Verify Wiring: Ensure getGlobalTopoRef correctly resolved the template and passed it to the Cell
168+
cell := &multigresv1alpha1.Cell{}
169+
if err := c.Get(ctx, types.NamespacedName{Name: clusterName + "-zone-a", Namespace: namespace}, cell); err != nil {
170+
t.Fatal("Expected Cell 'zone-a' to exist")
171+
}
172+
173+
expectedAddr := clusterName + "-global-topo-client." + namespace + ".svc:2379"
174+
if cell.Spec.GlobalTopoServer.Address != expectedAddr {
175+
t.Errorf("Wiring Bug! Cell has wrong Topo Address.\nGot: %q\nWant: %q",
176+
cell.Spec.GlobalTopoServer.Address, expectedAddr)
177+
}
164178
},
165179
},
166180
{
@@ -210,6 +224,17 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
210224
if *deploy.Spec.Replicas != 5 {
211225
t.Errorf("MultiAdmin did not use admin-core template, got replicas: %d", *deploy.Spec.Replicas)
212226
}
227+
228+
// Verify Wiring for independent template
229+
cell := &multigresv1alpha1.Cell{}
230+
if err := c.Get(ctx, types.NamespacedName{Name: clusterName + "-zone-a", Namespace: namespace}, cell); err != nil {
231+
t.Fatal("Expected Cell 'zone-a' to exist")
232+
}
233+
expectedAddr := clusterName + "-global-topo-client." + namespace + ".svc:2379"
234+
if cell.Spec.GlobalTopoServer.Address != expectedAddr {
235+
t.Errorf("Wiring Bug (Independent)! Cell has wrong Topo Address.\nGot: %q\nWant: %q",
236+
cell.Spec.GlobalTopoServer.Address, expectedAddr)
237+
}
213238
},
214239
},
215240
{

0 commit comments

Comments
 (0)