1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-26 05:14:13 +01:00

refactor(TestPodLifeTime): extract helper functions to package level

This commit is contained in:
Jan Chaloupka
2025-12-12 14:17:41 +01:00
parent 5d7a483dc8
commit d8d997a25d

View File

@@ -35,16 +35,18 @@ import (
"sigs.k8s.io/descheduler/test"
)
func TestPodLifeTime(t *testing.T) {
const nodeName1 = "n1"
buildTestNode1 := func() *v1.Node {
var (
olderPodCreationTime = metav1.NewTime(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC))
newerPodCreationTime = metav1.NewTime(time.Now())
)
func buildTestNode1() *v1.Node {
return test.BuildTestNode(nodeName1, 2000, 3000, 10, nil)
}
olderPodCreationTime := metav1.NewTime(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC))
newerPodCreationTime := metav1.NewTime(time.Now())
buildTestPodForNode1 := func(name string, creationTime metav1.Time, apply func(*v1.Pod)) *v1.Pod {
func buildTestPodForNode1(name string, creationTime metav1.Time, apply func(*v1.Pod)) *v1.Pod {
return test.BuildTestPod(name, 100, 0, nodeName1, func(pod *v1.Pod) {
pod.ObjectMeta.CreationTimestamp = creationTime
if apply != nil {
@@ -53,7 +55,7 @@ func TestPodLifeTime(t *testing.T) {
})
}
buildTestPodWithRSOwnerRefForNode1 := func(name string, creationTime metav1.Time, apply func(*v1.Pod)) *v1.Pod {
func buildTestPodWithRSOwnerRefForNode1(name string, creationTime metav1.Time, apply func(*v1.Pod)) *v1.Pod {
return buildTestPodForNode1(name, creationTime, func(pod *v1.Pod) {
test.SetRSOwnerRef(pod)
if apply != nil {
@@ -62,7 +64,7 @@ func TestPodLifeTime(t *testing.T) {
})
}
buildTestPodWithRSOwnerRefWithPendingPhaseForNode1 := func(name string, creationTime metav1.Time, apply func(*v1.Pod)) *v1.Pod {
func buildTestPodWithRSOwnerRefWithPendingPhaseForNode1(name string, creationTime metav1.Time, apply func(*v1.Pod)) *v1.Pod {
return buildTestPodWithRSOwnerRefForNode1(name, creationTime, func(pod *v1.Pod) {
pod.Status.Phase = "Pending"
if apply != nil {
@@ -71,6 +73,7 @@ func TestPodLifeTime(t *testing.T) {
})
}
func TestPodLifeTime(t *testing.T) {
var maxLifeTime uint = 600
testCases := []struct {
description string