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

tests: Show clearer error message when cleanup tests fail #1038

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions tests/cleanup_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package tests

import (
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
Expand Down Expand Up @@ -61,7 +62,23 @@ var _ = Describe("Cleanup", func() {
Expect(apiClient.List(ctx, list, client.MatchingLabels{
common.AppKubernetesManagedByLabel: "ssp-operator",
})).To(Succeed())
Expect(list.Items).To(BeEmpty(), "Some resources were not deleted.")

if len(list.Items) == 0 {
continue
}

// Collect resources to more readable names
objectTypesAndNames := make([]string, 0, len(list.Items))
for _, item := range list.Items {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move it to a new function that will return readable names?

objectTypesAndNames := getObjectTypesAndNames(list.Items)
Expect(objectTypesAndNames).To(BeEmpty(), "Some resources were not deleted.")

objectTypesAndNames = append(objectTypesAndNames, fmt.Sprintf("%s: %s/%s",
item.GetObjectKind().GroupVersionKind().String(),
item.GetNamespace(),
item.GetName(),
))

}

Expect(objectTypesAndNames).To(BeEmpty(), "Some resources were not deleted.")
}
})
})