From 04549edd098d36a01176e56ea91ad07f5a44faa9 Mon Sep 17 00:00:00 2001 From: Neo2308 Date: Sat, 2 Sep 2023 17:32:15 +0530 Subject: [PATCH] Fix scorecard test failures * Trim deprecation warning before unmarshalling output. Signed-off-by: Neo2308 --- test/common/scorecard.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/common/scorecard.go b/test/common/scorecard.go index 8aeeb71d6d0..39d2d0f5970 100644 --- a/test/common/scorecard.go +++ b/test/common/scorecard.go @@ -44,7 +44,7 @@ func ScorecardSpec(tc *testutils.TestContext, operatorType string) func() { "--wait-time", "2m") outputBytes, err = tc.Run(cmd) Expect(err).NotTo(HaveOccurred()) - Expect(json.Unmarshal(outputBytes, &output)).To(Succeed()) + Expect(json.Unmarshal(trimmedOutput(outputBytes), &output)).To(Succeed()) Expect(output.Items).To(HaveLen(1)) results := output.Items[0].Status.Results @@ -63,7 +63,7 @@ func ScorecardSpec(tc *testutils.TestContext, operatorType string) func() { if strings.ToLower(operatorType) != "go" { Expect(err).To(HaveOccurred()) } - Expect(json.Unmarshal(outputBytes, &output)).To(Succeed()) + Expect(json.Unmarshal(trimmedOutput(outputBytes), &output)).To(Succeed()) expected := map[string]v1alpha3.State{ // Basic suite. @@ -110,7 +110,7 @@ func ScorecardSpec(tc *testutils.TestContext, operatorType string) func() { "--wait-time", "4m") outputBytes, err = tc.Run(cmd) Expect(err).NotTo(HaveOccurred()) - Expect(json.Unmarshal(outputBytes, &output)).To(Succeed()) + Expect(json.Unmarshal(trimmedOutput(outputBytes), &output)).To(Succeed()) Expect(output.Items).To(HaveLen(1)) results := output.Items[0].Status.Results @@ -120,3 +120,10 @@ func ScorecardSpec(tc *testutils.TestContext, operatorType string) func() { }) } } + +// trimmedOutput trims the deprecation message (if present) from the output +func trimmedOutput(output []byte) []byte { + outputStr := string(output) + index := strings.Index(outputStr, "{") + return []byte(outputStr[index:]) +}