Skip to content

Commit 3558692

Browse files
Merge pull request #88 from numtide/simulated-error
test: rename errBoom to errSimulated for clarity
2 parents 6e84bab + ceed131 commit 3558692

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
636636
coreTpl, cellTpl, shardTpl, baseCluster, clusterName, namespace, finalizerName := setupFixtures(
637637
t,
638638
)
639-
errBoom := errors.New("boom")
639+
errSimulated := errors.New("simulated error for testing")
640640

641641
tests := map[string]struct {
642642
multigrescluster *multigresv1alpha1.MultigresCluster
@@ -716,7 +716,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
716716
"Error: Fetch Cluster Failed": {
717717
existingObjects: []client.Object{},
718718
failureConfig: &testutil.FailureConfig{
719-
OnGet: testutil.FailOnKeyName(clusterName, errBoom),
719+
OnGet: testutil.FailOnKeyName(clusterName, errSimulated),
720720
},
721721
},
722722
"Error: Add Finalizer Failed": {
@@ -725,7 +725,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
725725
},
726726
existingObjects: []client.Object{},
727727
failureConfig: &testutil.FailureConfig{
728-
OnUpdate: testutil.FailOnObjectName(clusterName, errBoom),
728+
OnUpdate: testutil.FailOnObjectName(clusterName, errSimulated),
729729
},
730730
},
731731
"Error: Remove Finalizer Failed": {
@@ -736,7 +736,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
736736
},
737737
existingObjects: []client.Object{},
738738
failureConfig: &testutil.FailureConfig{
739-
OnUpdate: testutil.FailOnObjectName(clusterName, errBoom),
739+
OnUpdate: testutil.FailOnObjectName(clusterName, errSimulated),
740740
},
741741
},
742742
"Error: CheckChildrenDeleted (List Cells Failed)": {
@@ -749,7 +749,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
749749
failureConfig: &testutil.FailureConfig{
750750
OnList: func(list client.ObjectList) error {
751751
if _, ok := list.(*multigresv1alpha1.CellList); ok {
752-
return errBoom
752+
return errSimulated
753753
}
754754
return nil
755755
},
@@ -765,7 +765,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
765765
failureConfig: &testutil.FailureConfig{
766766
OnList: func(list client.ObjectList) error {
767767
if _, ok := list.(*multigresv1alpha1.TableGroupList); ok {
768-
return errBoom
768+
return errSimulated
769769
}
770770
return nil
771771
},
@@ -781,7 +781,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
781781
failureConfig: &testutil.FailureConfig{
782782
OnList: func(list client.ObjectList) error {
783783
if _, ok := list.(*multigresv1alpha1.TopoServerList); ok {
784-
return errBoom
784+
return errSimulated
785785
}
786786
return nil
787787
},
@@ -790,7 +790,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
790790
"Error: Resolve CoreTemplate Failed": {
791791
existingObjects: []client.Object{coreTpl},
792792
failureConfig: &testutil.FailureConfig{
793-
OnGet: testutil.FailOnKeyName("default-core", errBoom),
793+
OnGet: testutil.FailOnKeyName("default-core", errSimulated),
794794
},
795795
},
796796
"Error: Resolve Admin Template Failed (Second Call)": {
@@ -808,37 +808,37 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
808808
},
809809
},
810810
failureConfig: &testutil.FailureConfig{
811-
OnGet: testutil.FailOnKeyName("admin-core-fail", errBoom),
811+
OnGet: testutil.FailOnKeyName("admin-core-fail", errSimulated),
812812
},
813813
},
814814
"Error: Create GlobalTopo Failed": {
815815
failureConfig: &testutil.FailureConfig{
816-
OnCreate: testutil.FailOnObjectName(clusterName+"-global-topo", errBoom),
816+
OnCreate: testutil.FailOnObjectName(clusterName+"-global-topo", errSimulated),
817817
},
818818
},
819819
"Error: Create MultiAdmin Failed": {
820820
failureConfig: &testutil.FailureConfig{
821-
OnCreate: testutil.FailOnObjectName(clusterName+"-multiadmin", errBoom),
821+
OnCreate: testutil.FailOnObjectName(clusterName+"-multiadmin", errSimulated),
822822
},
823823
},
824824
"Error: Resolve CellTemplate Failed": {
825825
failureConfig: &testutil.FailureConfig{
826-
OnGet: testutil.FailOnKeyName("default-cell", errBoom),
826+
OnGet: testutil.FailOnKeyName("default-cell", errSimulated),
827827
},
828828
},
829829
"Error: List Existing Cells Failed (Reconcile Loop)": {
830830
failureConfig: &testutil.FailureConfig{
831831
OnList: func(list client.ObjectList) error {
832832
if _, ok := list.(*multigresv1alpha1.CellList); ok {
833-
return errBoom
833+
return errSimulated
834834
}
835835
return nil
836836
},
837837
},
838838
},
839839
"Error: Create Cell Failed": {
840840
failureConfig: &testutil.FailureConfig{
841-
OnCreate: testutil.FailOnObjectName(clusterName+"-zone-a", errBoom),
841+
OnCreate: testutil.FailOnObjectName(clusterName+"-zone-a", errSimulated),
842842
},
843843
},
844844
"Error: Prune Cell Failed": {
@@ -853,27 +853,27 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
853853
},
854854
},
855855
failureConfig: &testutil.FailureConfig{
856-
OnDelete: testutil.FailOnObjectName(clusterName+"-zone-b", errBoom),
856+
OnDelete: testutil.FailOnObjectName(clusterName+"-zone-b", errSimulated),
857857
},
858858
},
859859
"Error: List Existing TableGroups Failed": {
860860
failureConfig: &testutil.FailureConfig{
861861
OnList: func(list client.ObjectList) error {
862862
if _, ok := list.(*multigresv1alpha1.TableGroupList); ok {
863-
return errBoom
863+
return errSimulated
864864
}
865865
return nil
866866
},
867867
},
868868
},
869869
"Error: Resolve ShardTemplate Failed": {
870870
failureConfig: &testutil.FailureConfig{
871-
OnGet: testutil.FailOnKeyName("default-shard", errBoom),
871+
OnGet: testutil.FailOnKeyName("default-shard", errSimulated),
872872
},
873873
},
874874
"Error: Create TableGroup Failed": {
875875
failureConfig: &testutil.FailureConfig{
876-
OnCreate: testutil.FailOnObjectName(clusterName+"-db1-tg1", errBoom),
876+
OnCreate: testutil.FailOnObjectName(clusterName+"-db1-tg1", errSimulated),
877877
},
878878
},
879879
"Error: Prune TableGroup Failed": {
@@ -888,7 +888,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
888888
},
889889
},
890890
failureConfig: &testutil.FailureConfig{
891-
OnDelete: testutil.FailOnObjectName(clusterName+"-orphan-tg", errBoom),
891+
OnDelete: testutil.FailOnObjectName(clusterName+"-orphan-tg", errSimulated),
892892
},
893893
},
894894
"Error: UpdateStatus (List Cells Failed)": {
@@ -899,7 +899,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
899899
if _, ok := list.(*multigresv1alpha1.CellList); ok {
900900
count++
901901
if count > 1 {
902-
return errBoom
902+
return errSimulated
903903
}
904904
}
905905
return nil
@@ -915,7 +915,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
915915
if _, ok := list.(*multigresv1alpha1.TableGroupList); ok {
916916
count++
917917
if count > 1 {
918-
return errBoom
918+
return errSimulated
919919
}
920920
}
921921
return nil
@@ -925,7 +925,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
925925
},
926926
"Error: Update Status Failed (API Error)": {
927927
failureConfig: &testutil.FailureConfig{
928-
OnStatusUpdate: testutil.FailOnObjectName(clusterName, errBoom),
928+
OnStatusUpdate: testutil.FailOnObjectName(clusterName, errSimulated),
929929
},
930930
},
931931
"Error: Global Topo Resolution Failed (During Cell Reconcile)": {
@@ -951,7 +951,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
951951
// Call 1: reconcileGlobalComponents -> ResolveCoreTemplate (Succeeds to proceed)
952952
// Call 2: reconcileCells -> getGlobalTopoRef -> ResolveCoreTemplate (Fails)
953953
if count == 2 {
954-
return errBoom
954+
return errSimulated
955955
}
956956
}
957957
return nil
@@ -983,7 +983,7 @@ func TestMultigresClusterReconciler_Reconcile_Failure(t *testing.T) {
983983
// Call 2: reconcileCells (Succeeds)
984984
// Call 3: reconcileDatabases -> getGlobalTopoRef (Fails)
985985
if count == 3 {
986-
return errBoom
986+
return errSimulated
987987
}
988988
}
989989
return nil

pkg/cluster-handler/controller/tablegroup/tablegroup_controller_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func TestTableGroupReconciler_Reconcile_Failure(t *testing.T) {
282282
_ = multigresv1alpha1.AddToScheme(scheme)
283283

284284
baseTG, tgName, namespace, clusterName, dbName, tgLabelName := setupFixtures(t)
285-
errBoom := errors.New("boom")
285+
errSimulated := errors.New("simulated error for testing")
286286

287287
tests := map[string]struct {
288288
tableGroup *multigresv1alpha1.TableGroup
@@ -294,7 +294,7 @@ func TestTableGroupReconciler_Reconcile_Failure(t *testing.T) {
294294
tableGroup: baseTG.DeepCopy(),
295295
existingObjects: []client.Object{},
296296
failureConfig: &testutil.FailureConfig{
297-
OnGet: testutil.FailOnKeyName(tgName, errBoom),
297+
OnGet: testutil.FailOnKeyName(tgName, errSimulated),
298298
},
299299
},
300300
"Error: Create/Update Shard Failed": {
@@ -303,7 +303,7 @@ func TestTableGroupReconciler_Reconcile_Failure(t *testing.T) {
303303
failureConfig: &testutil.FailureConfig{
304304
OnCreate: testutil.FailOnObjectName(
305305
fmt.Sprintf("%s-%s", tgName, "shard-0"),
306-
errBoom,
306+
errSimulated,
307307
),
308308
},
309309
},
@@ -313,7 +313,7 @@ func TestTableGroupReconciler_Reconcile_Failure(t *testing.T) {
313313
failureConfig: &testutil.FailureConfig{
314314
OnList: func(list client.ObjectList) error {
315315
if _, ok := list.(*multigresv1alpha1.ShardList); ok {
316-
return errBoom
316+
return errSimulated
317317
}
318318
return nil
319319
},
@@ -323,7 +323,7 @@ func TestTableGroupReconciler_Reconcile_Failure(t *testing.T) {
323323
tableGroup: baseTG.DeepCopy(),
324324
existingObjects: []client.Object{},
325325
failureConfig: &testutil.FailureConfig{
326-
OnList: testutil.FailObjListAfterNCalls(1, errBoom),
326+
OnList: testutil.FailObjListAfterNCalls(1, errSimulated),
327327
},
328328
},
329329
"Error: Delete Orphan Shard Failed": {
@@ -342,20 +342,21 @@ func TestTableGroupReconciler_Reconcile_Failure(t *testing.T) {
342342
"multigres.com/tablegroup": tgLabelName,
343343
},
344344
},
345+
Spec: multigresv1alpha1.ShardSpec{ShardName: "shard-0"},
345346
},
346347
},
347348
failureConfig: &testutil.FailureConfig{
348349
OnDelete: testutil.FailOnObjectName(
349350
fmt.Sprintf("%s-%s", tgName, "shard-0"),
350-
errBoom,
351+
errSimulated,
351352
),
352353
},
353354
},
354355
"Error: Update Status Failed": {
355356
tableGroup: baseTG.DeepCopy(),
356357
existingObjects: []client.Object{},
357358
failureConfig: &testutil.FailureConfig{
358-
OnStatusUpdate: testutil.FailOnObjectName(tgName, errBoom),
359+
OnStatusUpdate: testutil.FailOnObjectName(tgName, errSimulated),
359360
},
360361
},
361362
}

0 commit comments

Comments
 (0)