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>
This commit is contained in:
Anas Khan committed 2026-07-14 15:22:48 +05:30
1 parent 452fb31d95
commit 464582c40b
1 file changed
+4 -2
+4 -2
View File
@@ -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()