From e5bbedb6020afa880cb47060ab789486c63a30dd Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sat, 13 Dec 2025 13:56:26 +0100 Subject: [PATCH] refactor(TestPodLifeTime): extract generic filtering tests --- .../plugins/podlifetime/pod_lifetime_test.go | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index def1cf800..318f92541 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -143,26 +143,6 @@ func runPodLifeTimeTest(t *testing.T, tc podLifeTimeTestCase) { func TestPodLifeTime(t *testing.T) { var maxLifeTime uint = 600 testCases := []podLifeTimeTestCase{ - { - description: "1 pod matching label selector should be evicted", - args: &PodLifeTimeArgs{ - MaxPodLifeTimeSeconds: &maxLifeTime, - LabelSelector: &metav1.LabelSelector{ - MatchLabels: map[string]string{"foo": "bar"}, - }, - }, - pods: []*v1.Pod{ - buildTestPodWithRSOwnerRefForNode1("p12", olderPodCreationTime, func(pod *v1.Pod) { - pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} - }), - buildTestPodWithRSOwnerRefForNode1("p13", olderPodCreationTime, func(pod *v1.Pod) { - pod.ObjectMeta.Labels = map[string]string{"foo": "bar1"} - }), - }, - nodes: []*v1.Node{buildTestNode1()}, - expectedEvictedPodCount: 1, - expectedEvictedPods: []string{"p12"}, - }, { description: "No pod should be evicted since pod terminating", args: &PodLifeTimeArgs{ @@ -242,6 +222,38 @@ func TestPodLifeTime_EvictorConfiguration(t *testing.T) { } } +func TestPodLifeTime_GenericFiltering(t *testing.T) { + var maxLifeTime uint = 600 + testCases := []podLifeTimeTestCase{ + { + description: "1 pod matching label selector should be evicted", + args: &PodLifeTimeArgs{ + MaxPodLifeTimeSeconds: &maxLifeTime, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{"foo": "bar"}, + }, + }, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p12", olderPodCreationTime, func(pod *v1.Pod) { + pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} + }), + buildTestPodWithRSOwnerRefForNode1("p13", olderPodCreationTime, func(pod *v1.Pod) { + pod.ObjectMeta.Labels = map[string]string{"foo": "bar1"} + }), + }, + nodes: []*v1.Node{buildTestNode1()}, + expectedEvictedPodCount: 1, + expectedEvictedPods: []string{"p12"}, + }, + } + + for _, tc := range testCases { + t.Run(tc.description, func(t *testing.T) { + runPodLifeTimeTest(t, tc) + }) + } +} + func TestPodLifeTime_EvictionLimits(t *testing.T) { var maxLifeTime uint = 600 testCases := []podLifeTimeTestCase{