Skip to content

Commit

Permalink
e2e: Fail faster if checkup has failed
Browse files Browse the repository at this point in the history
Currently the e2e test waits for a JobComplete status, so if the checkup
job fails then the test hangs until the timeout.
Check for JobFailed condition and fail with an informative error fail.

Signed-off-by: Ram Lavi <ralavi@redhat.com>
  • Loading branch information
RamLavi committed Dec 3, 2023
1 parent 68cc0e3 commit 464d8f4
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions tests/checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package tests

import (
"context"
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -77,7 +78,21 @@ var _ = Describe("Checkup execution", func() {
})

It("should complete successfully", func() {
Eventually(getJobConditions, 15*time.Minute, 5*time.Second).Should(
Eventually(func() []batchv1.JobCondition {
jobConditions, err := getJobConditions()
Expect(err).NotTo(HaveOccurred())

for _, jobCondition := range jobConditions {
if jobCondition.Type == batchv1.JobFailed && jobCondition.Status == corev1.ConditionTrue {
configMap, err := client.CoreV1().ConfigMaps(testNamespace).Get(context.Background(), testConfigMapName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

Fail(fmt.Sprintf("checkup failed: %+v", prettifyData(configMap.Data)))
}
}

return jobConditions
}, 15*time.Minute, 5*time.Second).Should(
ContainElement(MatchFields(IgnoreExtras, Fields{
"Type": Equal(batchv1.JobComplete),
"Status": Equal(corev1.ConditionTrue),
Expand All @@ -92,6 +107,12 @@ var _ = Describe("Checkup execution", func() {
})
})

func prettifyData(data map[string]string) string {
dataPrettyJSON, err := json.MarshalIndent(data, "", "\t")
Expect(err).NotTo(HaveOccurred())
return string(dataPrettyJSON)
}

func setupCheckupPermissions() {
var (
err error
Expand Down Expand Up @@ -321,11 +342,11 @@ func pointer[T any](v T) *T {
return &v
}

func getJobConditions() []batchv1.JobCondition {
func getJobConditions() ([]batchv1.JobCondition, error) {
checkupJob, err := client.BatchV1().Jobs(testNamespace).Get(context.Background(), testCheckupJobName, metav1.GetOptions{})
if err != nil {
return []batchv1.JobCondition{}
return nil, err
}

return checkupJob.Status.Conditions
return checkupJob.Status.Conditions, nil
}

0 comments on commit 464d8f4

Please sign in to comment.