From 07dc0c61c5656d130cf869ba137cbca2783fb0f6 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 16:06:01 +0100 Subject: [PATCH] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- .../plugins/podlifetime/pod_lifetime_test.go | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index c13ec4cfe..20e75ab2e 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -70,10 +70,6 @@ func TestPodLifeTime(t *testing.T) { }) } - p16 := buildTestPodWithRSOwnerRefForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { - pod.Status.Phase = v1.PodUnknown - }) - var maxLifeTime uint = 600 testCases := []struct { description string @@ -609,7 +605,11 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{string(v1.PodSucceeded)}, }, - pods: []*v1.Pod{p16}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { + pod.Status.Phase = v1.PodUnknown + }), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -622,7 +622,11 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{string(v1.PodFailed)}, }, - pods: []*v1.Pod{p16}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { + pod.Status.Phase = v1.PodUnknown + }), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -635,7 +639,11 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{string(v1.PodUnknown)}, }, - pods: []*v1.Pod{p16}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { + pod.Status.Phase = v1.PodUnknown + }), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) {