Skip to content

Commit

Permalink
introduce component test
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed May 2, 2023
1 parent 2afed40 commit 3ca7577
Showing 1 changed file with 59 additions and 4 deletions.
63 changes: 59 additions & 4 deletions operator/test/component/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

klcv1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3"
apicommon "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3/common"
controllercommon "github.com/keptn/lifecycle-toolkit/operator/controllers/common"
"github.com/keptn/lifecycle-toolkit/operator/test/component/common"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -34,12 +35,10 @@ var _ = Describe("Task", Ordered, func() {
task *klcv1alpha3.KeptnTask
)
Context("with an existing TaskDefinition", func() {
BeforeEach(func() {
It("should end up in a failed state if the created job fails", func() {
taskDefinition = makeTaskDefinition(taskDefinitionName, namespace)
task = makeTask(name, namespace, taskDefinition.Name)
})

It("should end up in a failed state if the created job fails", func() {
By("Verifying that a job has been created")

Eventually(func(g Gomega) {
Expand Down Expand Up @@ -79,7 +78,63 @@ var _ = Describe("Task", Ordered, func() {
g.Expect(task.Status.Status).To(Equal(apicommon.StateFailed))
}, "10s").Should(Succeed())
})
It("succeed task if taskDefiniton is present in default KLT namespace", func() {
By("create default KLT namespace")

ns := &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: controllercommon.KLTNamespace,
},
}
err := k8sClient.Create(context.TODO(), ns)
Expect(err).To(BeNil())

taskDefinition = makeTaskDefinition(taskDefinitionName, controllercommon.KLTNamespace)
task = makeTask(name, namespace, taskDefinition.Name)

By("Verifying that a job has been created")

Eventually(func(g Gomega) {
err := k8sClient.Get(context.TODO(), types.NamespacedName{
Namespace: namespace,
Name: task.Name,
}, task)
g.Expect(err).To(BeNil())
g.Expect(task.Status.JobName).To(Not(BeEmpty()))
}, "10s").Should(Succeed())

createdJob := &batchv1.Job{}

err = k8sClient.Get(context.TODO(), types.NamespacedName{
Namespace: namespace,
Name: task.Status.JobName,
}, createdJob)

Expect(err).To(BeNil())

By("Setting the Job Status to complete")
createdJob.Status.Conditions = []batchv1.JobCondition{
{
Type: batchv1.JobComplete,
},
}

err = k8sClient.Status().Update(context.TODO(), createdJob)
Expect(err).To(BeNil())

Eventually(func(g Gomega) {
err := k8sClient.Get(context.TODO(), types.NamespacedName{
Namespace: namespace,
Name: task.Name,
}, task)
g.Expect(err).To(BeNil())
g.Expect(task.Status.Status).To(Equal(apicommon.StateSucceeded))
}, "10s").Should(Succeed())
})
It("should propagate labels and annotations to the job and job pod", func() {
taskDefinition = makeTaskDefinition(taskDefinitionName, namespace)
task = makeTask(name, namespace, taskDefinition.Name)

By("Verifying that a job has been created")

Eventually(func(g Gomega) {
Expand Down Expand Up @@ -126,7 +181,7 @@ var _ = Describe("Task", Ordered, func() {
err = k8sClient.Delete(context.TODO(), &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: taskDefinition.Status.Function.ConfigMap,
Namespace: namespace,
Namespace: taskDefinition.Namespace,
},
})
common.LogErrorIfPresent(err)
Expand Down

0 comments on commit 3ca7577

Please sign in to comment.