From ff430020601009eaf5a6709e2bb10a8bd221d7a8 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:43:07 +0100 Subject: [PATCH] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- .../plugins/podlifetime/pod_lifetime_test.go | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index c0b117dd5..4c5d1e965 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -62,7 +62,6 @@ func TestPodLifeTime(t *testing.T) { } // Setup pods, one should be evicted - p1 := buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil) p2 := buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil) // Setup pods, zero should be evicted @@ -132,7 +131,10 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p1, p2}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), + p2, + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, @@ -267,7 +269,11 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p1, p2, p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), + p2, + p9, + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 2, maxPodsToEvictPerNode: nil, @@ -278,7 +284,11 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p1, p2, p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), + p2, + p9, + }, nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNamespace: utilptr.To[uint](1), expectedEvictedPodCount: 1, @@ -288,7 +298,11 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p1, p2, p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), + p2, + p9, + }, nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNamespace: utilptr.To[uint](2), maxPodsToEvictTotal: utilptr.To[uint](1), @@ -299,7 +313,11 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p1, p2, p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), + p2, + p9, + }, nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNode: utilptr.To[uint](1), expectedEvictedPodCount: 1,