Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test]Add test helpers for MariaDBAccount #185

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
gibizer marked this conversation as resolved.
Show resolved Hide resolved
// 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)
}
Loading