Skip to content

Commit

Permalink
Merge pull request #336 from fmount/cronjob_envtest
Browse files Browse the repository at this point in the history
Add cronJob envTests
  • Loading branch information
openshift-merge-bot[bot] authored Oct 2, 2024
2 parents 1fc2563 + a47b9c2 commit 93c7969
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
9 changes: 9 additions & 0 deletions test/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

. "github.com/onsi/gomega" //revive:disable:dot-imports
"golang.org/x/exp/maps"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -325,3 +326,11 @@ func ManilaShareNotExists(name types.NamespacedName) {
g.Expect(k8s_errors.IsNotFound(err)).To(BeTrue())
}, timeout, interval).Should(Succeed())
}

func GetCronJob(name types.NamespacedName) *batchv1.CronJob {
cron := &batchv1.CronJob{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, name, cron)).Should(Succeed())
}, timeout, interval).Should(Succeed())
return cron
}
26 changes: 23 additions & 3 deletions test/functional/manila_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ var _ = Describe("Manila controller", func() {
})
It("initializes the status fields", func() {
Eventually(func(g Gomega) {
glance := GetManila(manilaName)
g.Expect(glance.Status.Conditions).To(HaveLen(14))
manila := GetManila(manilaName)
g.Expect(manila.Status.Conditions).To(HaveLen(14))

g.Expect(glance.Status.DatabaseHostname).To(Equal(""))
g.Expect(manila.Status.DatabaseHostname).To(Equal(""))
}, timeout*2, interval).Should(Succeed())
})
It("is not Ready", func() {
Expand Down Expand Up @@ -297,6 +297,26 @@ var _ = Describe("Manila controller", func() {
th.AssertServiceExists(manilaTest.ManilaServicePublic)
th.AssertServiceExists(manilaTest.ManilaServiceInternal)
})
It("configures DB Purge job", func() {
Eventually(func(g Gomega) {
manila := GetManila(manilaTest.Instance)
cron := GetCronJob(manilaTest.DBPurgeCronJob)
g.Expect(cron.Spec.Schedule).To(Equal(manila.Spec.DBPurge.Schedule))
}, timeout, interval).Should(Succeed())
})
It("update DB Purge job", func() {
Eventually(func(g Gomega) {
manila := GetManila(manilaTest.Instance)
manila.Spec.DBPurge.Schedule = "*/30 * * * *"
g.Expect(k8sClient.Update(ctx, manila)).To(Succeed())
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
manila := GetManila(manilaTest.Instance)
cron := GetCronJob(manilaTest.DBPurgeCronJob)
g.Expect(cron.Spec.Schedule).To(Equal(manila.Spec.DBPurge.Schedule))
}, timeout, interval).Should(Succeed())
})
})
When("Manila CR instance is deleted", func() {
BeforeEach(func() {
Expand Down
5 changes: 5 additions & 0 deletions test/functional/manila_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type ManilaTestData struct {
CABundleSecret types.NamespacedName
InternalCertSecret types.NamespacedName
PublicCertSecret types.NamespacedName
DBPurgeCronJob types.NamespacedName
}

// GetManilaTestData is a function that initialize the ManilaTestData
Expand Down Expand Up @@ -191,5 +192,9 @@ func GetManilaTestData(manilaName types.NamespacedName) ManilaTestData {
Namespace: manilaName.Namespace,
Name: PublicCertSecretName,
},
DBPurgeCronJob: types.NamespacedName{
Namespace: manilaName.Namespace,
Name: fmt.Sprintf("%s-db-purge", manilaName.Name),
},
}
}

0 comments on commit 93c7969

Please sign in to comment.