From 9ed796505d0b40ebeed2ed09fe0bc920881ec514 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Tue, 20 Feb 2024 10:27:58 +0100 Subject: [PATCH] [helpers] MariaDBDatabase and MariaDBAccount create helpers Add func to create MariaDBDatabase and MariaDBAccount resources for envtest usage. related to Jira: OSPRH-4547 --- api/test/helpers/crd.go | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/api/test/helpers/crd.go b/api/test/helpers/crd.go index 5da605bc..092670fb 100644 --- a/api/test/helpers/crd.go +++ b/api/test/helpers/crd.go @@ -151,6 +151,30 @@ func (tc *TestHelper) DeleteDBService(name types.NamespacedName) { }, tc.Timeout, tc.Interval).Should(gomega.Succeed()) } +// CreateMariaDBDatabase creates a new MariaDBDatabase instance with the specified namespace in the Kubernetes cluster. +func (tc *TestHelper) CreateMariaDBDatabase(namespace string, dbName string, spec mariadbv1.MariaDBDatabaseSpec) types.NamespacedName { + name := types.NamespacedName{ + Name: dbName, + Namespace: namespace, + } + + db := &mariadbv1.MariaDBDatabase{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "mariadb.openstack.org/v1beta1", + Kind: "MariaDBDatabase", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: dbName, + Namespace: namespace, + }, + Spec: spec, + } + + gomega.Expect(tc.K8sClient.Create(tc.Ctx, db)).Should(gomega.Succeed()) + + return name +} + // GetMariaDBDatabase waits for and retrieves a MariaDBDatabase resource from the Kubernetes cluster // // Example: @@ -218,6 +242,30 @@ func (tc *TestHelper) AssertMariaDBDatabaseDoesNotExist(name types.NamespacedNam }, tc.Timeout, tc.Interval).Should(gomega.Succeed()) } +// CreateMariaDBAccount creates a new MariaDBAccount instance with the specified namespace in the Kubernetes cluster. +func (tc *TestHelper) CreateMariaDBAccount(namespace string, acctName string, spec mariadbv1.MariaDBAccountSpec) types.NamespacedName { + name := types.NamespacedName{ + Name: acctName, + Namespace: namespace, + } + + db := &mariadbv1.MariaDBAccount{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "mariadb.openstack.org/v1beta1", + Kind: "MariaDBAccount", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: acctName, + Namespace: namespace, + }, + Spec: spec, + } + + gomega.Expect(tc.K8sClient.Create(tc.Ctx, db)).Should(gomega.Succeed()) + + return name +} + // GetMariaDBAccount waits for and retrieves a MariaDBAccount resource from the Kubernetes cluster func (tc *TestHelper) GetMariaDBAccount(name types.NamespacedName) *mariadbv1.MariaDBAccount { instance := &mariadbv1.MariaDBAccount{}