Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: Fail faster if checkup has failed #43

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}