From 62a3ac4182b2868eb1a260ba053142d0720b5bef Mon Sep 17 00:00:00 2001 From: Justin Kulikauskas Date: Wed, 20 Sep 2023 13:54:25 -0400 Subject: [PATCH] Add debug to enforce with status test This test has been flakey - the last check for Compliant events has been coming back empty unexpectedly. This will print information about all of the events to help understand what is happening. Signed-off-by: Justin Kulikauskas --- test/e2e/case34_enforce_w_status_test.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/test/e2e/case34_enforce_w_status_test.go b/test/e2e/case34_enforce_w_status_test.go index c1c556b2..99ca5046 100644 --- a/test/e2e/case34_enforce_w_status_test.go +++ b/test/e2e/case34_enforce_w_status_test.go @@ -4,13 +4,15 @@ package e2e import ( + "strconv" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "open-cluster-management.io/config-policy-controller/test/utils" ) -var _ = Describe("Test compliance events of enforced policies that define a status", Ordered, func() { +var _ = Describe("Test compliance events of enforced policies that define a status", func() { const ( rsrcPath = "../resources/case34_enforce_w_status/" policyYAML = rsrcPath + "policy.yaml" @@ -60,7 +62,25 @@ var _ = Describe("Test compliance events of enforced policies that define a stat }, defaultTimeoutSeconds, 5).ShouldNot(BeEmpty()) }) - AfterAll(func() { + AfterEach(func() { + if CurrentSpecReport().Failed() { + events := utils.GetMatchingEvents(clientManaged, testNamespace, + policyName, ".*", ".*", defaultTimeoutSeconds) + + By("Test failed, printing compliance events for debugging, event count = " + strconv.Itoa(len(events))) + for _, ev := range events { + GinkgoWriter.Println("---") + GinkgoWriter.Println("Name:", ev.Name) + GinkgoWriter.Println("Reason:", ev.Reason) + GinkgoWriter.Println("Message:", ev.Message) + GinkgoWriter.Println("FirstTimestamp:", ev.FirstTimestamp) + GinkgoWriter.Println("LastTimestamp:", ev.LastTimestamp) + GinkgoWriter.Println("Count:", ev.Count) + GinkgoWriter.Println("Type:", ev.Type) + GinkgoWriter.Println("---") + } + } + utils.Kubectl("delete", "policy", policyName, "-n", "managed", "--ignore-not-found") configPlc := utils.GetWithTimeout(clientManagedDynamic, gvrConfigPolicy, cfgPlcName, "managed", false, defaultTimeoutSeconds,