Skip to content

Commit

Permalink
Merge pull request #185 from gibizer/adapt-test-helpers
Browse files Browse the repository at this point in the history
[test]Add test helpers for MariaDBAccount
  • Loading branch information
openshift-merge-bot[bot] authored Jan 31, 2024
2 parents 5ad30f7 + 4b72434 commit dd95ba8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions api/test/helpers/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (tc *TestHelper) SimulateMariaDBDatabaseCompleted(name types.NamespacedName
gomega.Eventually(func(g gomega.Gomega) {
db := tc.GetMariaDBDatabase(name)
db.Status.Completed = true
db.Status.Conditions.MarkTrue(mariadbv1.MariaDBDatabaseReadyCondition, "Ready")
// This can return conflict so we have the gomega.Eventually block to retry
g.Expect(tc.K8sClient.Status().Update(tc.Ctx, db)).To(gomega.Succeed())

Expand All @@ -193,3 +194,25 @@ func (tc *TestHelper) AssertMariaDBDatabaseDoesNotExist(name types.NamespacedNam
g.Expect(k8s_errors.IsNotFound(err)).To(gomega.BeTrue())
}, tc.Timeout, tc.Interval).Should(gomega.Succeed())
}

// GetMariaDBAccount waits for and retrieves a MariaDBAccount resource from the Kubernetes cluster
func (tc *TestHelper) GetMariaDBAccount(name types.NamespacedName) *mariadbv1.MariaDBAccount {
instance := &mariadbv1.MariaDBAccount{}
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(tc.K8sClient.Get(tc.Ctx, name, instance)).Should(gomega.Succeed())
}, tc.Timeout, tc.Interval).Should(gomega.Succeed())
return instance
}

// SimulateMariaDBAccountCompleted simulates that the MariaDBAccount is created in the DB
func (tc *TestHelper) SimulateMariaDBAccountCompleted(name types.NamespacedName) {
gomega.Eventually(func(g gomega.Gomega) {
acc := tc.GetMariaDBAccount(name)
acc.Status.Conditions.MarkTrue(mariadbv1.MariaDBAccountReadyCondition, "Ready")
// This can return conflict so we have the gomega.Eventually block to retry
g.Expect(tc.K8sClient.Status().Update(tc.Ctx, acc)).To(gomega.Succeed())

}, tc.Timeout, tc.Interval).Should(gomega.Succeed())

tc.Logger.Info("Simulated DB Account completed", "on", name)
}

0 comments on commit dd95ba8

Please sign in to comment.