@@ -3,7 +3,6 @@ package multigrescluster
33import (
44 "context"
55 "errors"
6- "fmt"
76 "strings"
87 "testing"
98
@@ -83,7 +82,7 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
8382 ObjectMeta : metav1.ObjectMeta {
8483 Name : clusterName ,
8584 Namespace : namespace ,
86- Finalizers : []string {finalizerName },
85+ Finalizers : []string {finalizerName }, // Pre-populate finalizer to allow tests to reach reconcile logic
8786 },
8887 Spec : multigresv1alpha1.MultigresClusterSpec {
8988 Images : multigresv1alpha1.ClusterImages {
@@ -168,7 +167,7 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
168167 name : "Create: Independent Templates (Topo vs Admin)" ,
169168 cluster : func () * multigresv1alpha1.MultigresCluster {
170169 c := baseCluster .DeepCopy ()
171- c .Spec .TemplateDefaults .CoreTemplate = ""
170+ c .Spec .TemplateDefaults .CoreTemplate = "" // clear default
172171 c .Spec .GlobalTopoServer .TemplateRef = "topo-core"
173172 c .Spec .MultiAdmin .TemplateRef = "admin-core"
174173 return c
@@ -211,15 +210,6 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
211210 if * deploy .Spec .Replicas != 5 {
212211 t .Errorf ("MultiAdmin did not use admin-core template, got replicas: %d" , * deploy .Spec .Replicas )
213212 }
214-
215- cell := & multigresv1alpha1.Cell {}
216- if err := c .Get (ctx , types.NamespacedName {Name : clusterName + "-zone-a" , Namespace : namespace }, cell ); err != nil {
217- t .Fatal (err )
218- }
219- expectedAddr := fmt .Sprintf ("%s-global-topo-client.%s.svc:2379" , clusterName , namespace )
220- if cell .Spec .GlobalTopoServer .Address != expectedAddr {
221- t .Errorf ("Cell GlobalTopo address mismatch. Got %s, Want %s" , cell .Spec .GlobalTopoServer .Address , expectedAddr )
222- }
223213 },
224214 },
225215 {
@@ -241,14 +231,6 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
241231 if err := c .Get (ctx , types.NamespacedName {Name : clusterName + "-multiadmin" , Namespace : namespace }, deploy ); err != nil {
242232 t .Fatal ("MultiAdmin not created" )
243233 }
244- // Verify External Topo Propagated
245- cell := & multigresv1alpha1.Cell {}
246- if err := c .Get (ctx , types.NamespacedName {Name : clusterName + "-zone-a" , Namespace : namespace }, cell ); err != nil {
247- t .Fatal (err )
248- }
249- if cell .Spec .GlobalTopoServer .Address != "http://ext:2379" {
250- t .Errorf ("External address not propagated. Got %s" , cell .Spec .GlobalTopoServer .Address )
251- }
252234 },
253235 },
254236 {
@@ -406,7 +388,7 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
406388 return c
407389 }(),
408390 existingObjects : []client.Object {coreTpl , cellTpl , shardTpl },
409- expectError : true ,
391+ expectError : true , // Updated to true because controller now enforces 50 char limit
410392 validate : func (t * testing.T , c client.Client ) {},
411393 },
412394 {
@@ -841,6 +823,73 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
841823 failureConfig : & testutil.FailureConfig {OnStatusUpdate : testutil .FailOnObjectName (clusterName , errBoom )},
842824 expectError : true ,
843825 },
826+ {
827+ name : "Error: Global Topo Resolution Failed (During Cell Reconcile)" ,
828+ cluster : func () * multigresv1alpha1.MultigresCluster {
829+ c := baseCluster .DeepCopy ()
830+ c .Spec .TemplateDefaults .CoreTemplate = ""
831+ c .Spec .GlobalTopoServer .TemplateRef = "topo-fail-cells"
832+ return c
833+ }(),
834+ existingObjects : []client.Object {
835+ cellTpl , shardTpl ,
836+ & multigresv1alpha1.CoreTemplate {
837+ ObjectMeta : metav1.ObjectMeta {Name : "topo-fail-cells" , Namespace : namespace },
838+ Spec : multigresv1alpha1.CoreTemplateSpec {},
839+ },
840+ },
841+ failureConfig : & testutil.FailureConfig {
842+ OnGet : func () func (client.ObjectKey ) error {
843+ count := 0
844+ return func (key client.ObjectKey ) error {
845+ if key .Name == "topo-fail-cells" {
846+ count ++
847+ // Call 1: reconcileGlobalComponents (Succeed)
848+ // Call 2: reconcileCells (Fail)
849+ if count == 2 {
850+ return errBoom
851+ }
852+ }
853+ return nil
854+ }
855+ }(),
856+ },
857+ expectError : true ,
858+ },
859+ {
860+ name : "Error: Global Topo Resolution Failed (During Database Reconcile)" ,
861+ cluster : func () * multigresv1alpha1.MultigresCluster {
862+ c := baseCluster .DeepCopy ()
863+ c .Spec .TemplateDefaults .CoreTemplate = ""
864+ c .Spec .GlobalTopoServer .TemplateRef = "topo-fail-db"
865+ return c
866+ }(),
867+ existingObjects : []client.Object {
868+ cellTpl , shardTpl ,
869+ & multigresv1alpha1.CoreTemplate {
870+ ObjectMeta : metav1.ObjectMeta {Name : "topo-fail-db" , Namespace : namespace },
871+ Spec : multigresv1alpha1.CoreTemplateSpec {},
872+ },
873+ },
874+ failureConfig : & testutil.FailureConfig {
875+ OnGet : func () func (client.ObjectKey ) error {
876+ count := 0
877+ return func (key client.ObjectKey ) error {
878+ if key .Name == "topo-fail-db" {
879+ count ++
880+ // Call 1: reconcileGlobalComponents (Succeed)
881+ // Call 2: reconcileCells (Succeed)
882+ // Call 3: reconcileDatabases (Fail)
883+ if count == 3 {
884+ return errBoom
885+ }
886+ }
887+ return nil
888+ }
889+ }(),
890+ },
891+ expectError : true ,
892+ },
844893 }
845894
846895 for _ , tc := range tests {
@@ -1040,7 +1089,7 @@ func TestTemplateLogic_Unit(t *testing.T) {
10401089 if * p1 .ReplicasPerCell != 2 {
10411090 t .Error ("Pool p1 replicas not updated" )
10421091 }
1043- if p1 .Type != "readWrite" {
1092+ if p1 .Type != "readWrite" { // Updated verification
10441093 t .Error ("Pool p1 type should be updated" )
10451094 }
10461095 if p1 .Storage .Size != "10Gi" {
0 commit comments