Skip to content

Commit

Permalink
[helpers] MariaDBDatabase and MariaDBAccount create helpers
Browse files Browse the repository at this point in the history
Add func to create MariaDBDatabase and MariaDBAccount resources
for envtest usage.

related to Jira: OSPRH-4547
  • Loading branch information
stuggi committed Feb 20, 2024
1 parent b37bc25 commit 9ed7965
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions api/test/helpers/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit 9ed7965

Please sign in to comment.