From 464582c40b23d208eeb87ec91b0bfb8639b1ed6e Mon Sep 17 00:00:00 2001 From: Anas Khan <83116240+anxkhn@users.noreply.github.com> Date: Mon, 6 Jul 2026 01:44:50 +0530 Subject: [PATCH] test: assert preferred anti-affinity count in testPodSpecPlacement testPodSpecPlacement accepts a pref parameter but never asserts the preferred anti-affinity count, so the PreferredDuringScheduling branch of SetNodeAntiAffinityForPod went unverified. The assertion was dropped in b91f4211c9 when the separate preferred flag was removed from SetNodeAntiAffinityForPod, leaving pref unused. Restore the missing assertion so the helper validates both the required and preferred term counts. Drop the third empty-placement case, which became an exact duplicate of the second once the two-boolean API was collapsed and now adds no coverage. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com> --- pkg/operator/k8sutil/pod_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/operator/k8sutil/pod_test.go b/pkg/operator/k8sutil/pod_test.go index 5532edffe..1021197ee 100644 --- a/pkg/operator/k8sutil/pod_test.go +++ b/pkg/operator/k8sutil/pod_test.go @@ -190,10 +190,13 @@ func testPodSpecPlacement(t *testing.T, requiredDuringScheduling bool, req, pref placement.ApplyToPodSpec(&spec) SetNodeAntiAffinityForPod(&spec, requiredDuringScheduling, v1.LabelHostname, map[string]string{"app": "mon"}, nil) - // should have a required anti-affinity and no preferred anti-affinity + // should have the expected number of required and preferred anti-affinity terms assert.Equal(t, req, len(spec.Affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution)) + assert.Equal(t, + pref, + len(spec.Affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution)) } func makePlacement() cephv1.Placement { @@ -220,7 +223,6 @@ func TestPodSpecPlacement(t *testing.T) { p := cephv1.Placement{} testPodSpecPlacement(t, true, 1, 0, &p) testPodSpecPlacement(t, false, 0, 1, &p) - testPodSpecPlacement(t, false, 0, 0, &p) // crd has other preferred and required anti-affinity setting p = makePlacement()