From 1b7c117e8adcf4b773380fa1562db53ffe899b76 Mon Sep 17 00:00:00 2001 From: Anas Khan Date: Tue, 14 Jul 2026 13:42:02 +0530 Subject: [PATCH] test: assert hpa resource-configured error after the results loop (#1685) TestHPAAnalyzerWithExistingScaleTargetRefWithoutSpecifyingResources placed its "if !errorFound { t.Error(...) }" assertion inside the outer "for _, analysis := range analysisResults" loop. When the analyzer emits zero results (exactly the regression this test guards against, the "does not have resource configured." detection breaking), the outer loop body never runs, the assertion is skipped, and the test passes green. Move the assertion after the outer loop and break out of it once the error is found, matching the sibling HPA tests (TestHPAAnalyzerWithUnsuportedScaleTargetRef, TestHPAAnalyzerWithNonExistentScaleTargetRef). Also drop the dead break that sat inside the inner loop after its own break. Test-only change. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com> Co-authored-by: Alex Jones <1235925+AlexsJones@users.noreply.github.com> --- pkg/analyzer/hpa_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/analyzer/hpa_test.go b/pkg/analyzer/hpa_test.go index 62b273f5..0eacf2a4 100644 --- a/pkg/analyzer/hpa_test.go +++ b/pkg/analyzer/hpa_test.go @@ -491,14 +491,14 @@ func TestHPAAnalyzerWithExistingScaleTargetRefWithoutSpecifyingResources(t *test errorFound = true break } - if errorFound { - break - } } - if !errorFound { - t.Error("expected error 'does not have resource configured.' not found in analysis results") + if errorFound { + break } } + if !errorFound { + t.Error("expected error 'does not have resource configured.' not found in analysis results") + } } func TestHPAAnalyzerNamespaceFiltering(t *testing.T) {