|
5 | 5 | "context"
|
6 | 6 | "encoding/json"
|
7 | 7 | "fmt"
|
| 8 | + "maps" |
8 | 9 | "sort"
|
9 | 10 | "testing"
|
10 | 11 |
|
@@ -1425,6 +1426,75 @@ func TestValidationsRunOnReconcile(t *testing.T) {
|
1425 | 1426 | assert.Equal(t, fmt.Sprintf("Multiple clusters with the same name (%s) are not allowed", duplicateName), mrs.Status.Message)
|
1426 | 1427 | }
|
1427 | 1428 |
|
| 1429 | +func TestReconcileDisableReconciliationAnnotation(t *testing.T) { |
| 1430 | + tests := []struct { |
| 1431 | + name string |
| 1432 | + annotations map[string]string |
| 1433 | + expectedPhase status.Phase |
| 1434 | + expectedReconcileResult reconcile.Result |
| 1435 | + }{ |
| 1436 | + { |
| 1437 | + name: "reconciliation disabled when annotation is true", |
| 1438 | + annotations: map[string]string{util.DisableReconciliation: util.DisableReconciliationValue}, |
| 1439 | + expectedPhase: status.PhaseDisabled, |
| 1440 | + expectedReconcileResult: reconcile.Result{Requeue: false, RequeueAfter: 0}, |
| 1441 | + }, |
| 1442 | + { |
| 1443 | + name: "reconciliation proceeds when annotation is false", |
| 1444 | + annotations: map[string]string{util.DisableReconciliation: "false"}, |
| 1445 | + expectedPhase: status.PhaseRunning, |
| 1446 | + expectedReconcileResult: reconcile.Result{RequeueAfter: util.TWENTY_FOUR_HOURS}, |
| 1447 | + }, |
| 1448 | + { |
| 1449 | + name: "reconciliation proceeds when annotation is empty string", |
| 1450 | + annotations: map[string]string{util.DisableReconciliation: ""}, |
| 1451 | + expectedPhase: status.PhaseRunning, |
| 1452 | + expectedReconcileResult: reconcile.Result{RequeueAfter: util.TWENTY_FOUR_HOURS}, |
| 1453 | + }, |
| 1454 | + { |
| 1455 | + name: "reconciliation proceeds when annotation is arbitrary value", |
| 1456 | + annotations: map[string]string{util.DisableReconciliation: "some-other-value"}, |
| 1457 | + expectedPhase: status.PhaseRunning, |
| 1458 | + expectedReconcileResult: reconcile.Result{RequeueAfter: util.TWENTY_FOUR_HOURS}, |
| 1459 | + }, |
| 1460 | + { |
| 1461 | + name: "reconciliation proceeds when annotation is absent", |
| 1462 | + expectedPhase: status.PhaseRunning, |
| 1463 | + expectedReconcileResult: reconcile.Result{RequeueAfter: util.TWENTY_FOUR_HOURS}, |
| 1464 | + }, |
| 1465 | + } |
| 1466 | + |
| 1467 | + for _, tt := range tests { |
| 1468 | + t.Run(tt.name, func(t *testing.T) { |
| 1469 | + ctx := context.Background() |
| 1470 | + mrs := mdbmulti.DefaultMultiReplicaSetBuilder().SetClusterSpecList(clusters).Build() |
| 1471 | + |
| 1472 | + // Set up test annotations |
| 1473 | + if mrs.Annotations == nil { |
| 1474 | + mrs.Annotations = map[string]string{} |
| 1475 | + } |
| 1476 | + maps.Copy(mrs.Annotations, tt.annotations) |
| 1477 | + |
| 1478 | + reconciler, client, _, _ := defaultMultiReplicaSetReconciler(ctx, nil, "", "", mrs) |
| 1479 | + |
| 1480 | + // Update the resource with the annotation |
| 1481 | + err := client.Update(ctx, mrs) |
| 1482 | + assert.NoError(t, err) |
| 1483 | + |
| 1484 | + // Reconcile should return without error and with expected result |
| 1485 | + result, err := reconciler.Reconcile(ctx, requestFromObject(mrs)) |
| 1486 | + assert.NoError(t, err) |
| 1487 | + assert.Equal(t, tt.expectedReconcileResult, result) |
| 1488 | + |
| 1489 | + // Fetch the updated resource to check the status |
| 1490 | + err = client.Get(ctx, kube.ObjectKey(mrs.Namespace, mrs.Name), mrs) |
| 1491 | + assert.NoError(t, err) |
| 1492 | + |
| 1493 | + assert.Equal(t, tt.expectedPhase, mrs.Status.Phase) |
| 1494 | + }) |
| 1495 | + } |
| 1496 | +} |
| 1497 | + |
1428 | 1498 | func assertClusterpresent(t *testing.T, m map[string]int, specs mdb.ClusterSpecList, arr []int) {
|
1429 | 1499 | tmp := make([]int, 0)
|
1430 | 1500 | for _, s := range specs {
|
|
0 commit comments