Skip to content

Commit

Permalink
Add stopped condition tests
Browse files Browse the repository at this point in the history
Signed-off-by: d-kuro <kurosawa7620@gmail.com>
  • Loading branch information
d-kuro committed Oct 25, 2023
1 parent 02b9305 commit 2450ca4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions controllers/mysqlcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1922,4 +1922,58 @@ var _ = Describe("MySQLCluster reconciler", func() {
return nil
}).Should(Succeed())
})

It("should reconciliation stopped", func() {
cluster := testNewMySQLCluster("test")
err := k8sClient.Create(ctx, cluster)
Expect(err).NotTo(HaveOccurred())

By("setting reconcile stop annotation")
cluster.Annotations[constants.AnnReconciliationStopped] = "true"
err = k8sClient.Update(ctx, cluster)
Expect(err).NotTo(HaveOccurred())

By("checking condition is false")
Eventually(func() error {
cluster = &mocov1beta2.MySQLCluster{}
if err = k8sClient.Get(ctx, client.ObjectKey{Namespace: "test", Name: "test"}, cluster); err != nil {
return err
}
cond := meta.FindStatusCondition(cluster.Status.Conditions, mocov1beta2.ConditionReconciliationActive)
if cond == nil {
return fmt.Errorf("condition does not exists")
}
if cond.Status != metav1.ConditionFalse {
return fmt.Errorf("condition is not false")
}
return nil
}).Should(Succeed())
})

It("should clustering stopped", func() {
cluster := testNewMySQLCluster("test")
err := k8sClient.Create(ctx, cluster)
Expect(err).NotTo(HaveOccurred())

By("setting clustering stop annotation")
cluster.Annotations[constants.AnnClusteringStopped] = "true"
err = k8sClient.Update(ctx, cluster)
Expect(err).NotTo(HaveOccurred())

By("checking condition is false")
Eventually(func() error {
cluster = &mocov1beta2.MySQLCluster{}
if err = k8sClient.Get(ctx, client.ObjectKey{Namespace: "test", Name: "test"}, cluster); err != nil {
return err
}
cond := meta.FindStatusCondition(cluster.Status.Conditions, mocov1beta2.ConditionReconciliationActive)
if cond == nil {
return fmt.Errorf("condition does not exists")
}
if cond.Status != metav1.ConditionFalse {
return fmt.Errorf("condition is not false")
}
return nil
}).Should(Succeed())
})
})

0 comments on commit 2450ca4

Please sign in to comment.