From 3283635149e3b856c3c39a20e731e898885ebafa Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sat, 20 Dec 2025 15:17:06 +0100 Subject: [PATCH] refactor(defaultevictor_test): move newProtectedStorageClassesConfig to package level Move the newProtectedStorageClassesConfig helper function from local scope to package level so it can be reused by both TestDefaultEvictorFilter and Test_protectedPVCStorageClasses, eliminating code duplication. --- .../defaultevictor/defaultevictor_test.go | 61 ++++++------------- 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/pkg/framework/plugins/defaultevictor/defaultevictor_test.go b/pkg/framework/plugins/defaultevictor/defaultevictor_test.go index 6ddb4f39d..c914fefe3 100644 --- a/pkg/framework/plugins/defaultevictor/defaultevictor_test.go +++ b/pkg/framework/plugins/defaultevictor/defaultevictor_test.go @@ -68,6 +68,18 @@ func buildTestPod(name string, nodeName string, apply func(*v1.Pod)) *v1.Pod { return test.BuildTestPod(name, 400, 0, nodeName, apply) } +func newProtectedStorageClassesConfig(storageClassNames ...string) *PodProtectionsConfig { + protectedClasses := make([]ProtectedStorageClass, len(storageClassNames)) + for i, name := range storageClassNames { + protectedClasses[i] = ProtectedStorageClass{Name: name} + } + return &PodProtectionsConfig{ + PodsWithPVC: &PodsWithPVCConfig{ + ProtectedStorageClasses: protectedClasses, + }, + } +} + func TestDefaultEvictorPreEvictionFilter(t *testing.T) { n1 := buildTestNode("node1", nil) @@ -790,15 +802,7 @@ func TestDefaultEvictorFilter(t *testing.T) { }, podProtections: PodProtections{ ExtraEnabled: []PodProtection{PodsWithPVC}, - Config: &PodProtectionsConfig{ - PodsWithPVC: &PodsWithPVCConfig{ - ProtectedStorageClasses: []ProtectedStorageClass{ - { - Name: "standard", - }, - }, - }, - }, + Config: newProtectedStorageClassesConfig("standard"), }, pvcs: []*v1.PersistentVolumeClaim{ test.BuildTestPVC("foo", "standard"), @@ -815,15 +819,7 @@ func TestDefaultEvictorFilter(t *testing.T) { }, podProtections: PodProtections{ ExtraEnabled: []PodProtection{PodsWithPVC}, - Config: &PodProtectionsConfig{ - PodsWithPVC: &PodsWithPVCConfig{ - ProtectedStorageClasses: []ProtectedStorageClass{ - { - Name: "protected", - }, - }, - }, - }, + Config: newProtectedStorageClassesConfig("protected"), }, pvcs: []*v1.PersistentVolumeClaim{ test.BuildTestPVC("foo", "unprotected"), @@ -840,15 +836,7 @@ func TestDefaultEvictorFilter(t *testing.T) { }, podProtections: PodProtections{ ExtraEnabled: []PodProtection{PodsWithPVC}, - Config: &PodProtectionsConfig{ - PodsWithPVC: &PodsWithPVCConfig{ - ProtectedStorageClasses: []ProtectedStorageClass{ - { - Name: "protected", - }, - }, - }, - }, + Config: newProtectedStorageClassesConfig("protected"), }, pvcs: []*v1.PersistentVolumeClaim{}, result: false, @@ -878,15 +866,7 @@ func TestDefaultEvictorFilter(t *testing.T) { }, podProtections: PodProtections{ ExtraEnabled: []PodProtection{PodsWithPVC}, - Config: &PodProtectionsConfig{ - PodsWithPVC: &PodsWithPVCConfig{ - ProtectedStorageClasses: []ProtectedStorageClass{ - { - Name: "protected", - }, - }, - }, - }, + Config: newProtectedStorageClassesConfig("protected"), }, pvcs: []*v1.PersistentVolumeClaim{ test.BuildTestPVC("protected", "protected"), @@ -1161,14 +1141,7 @@ func Test_protectedPVCStorageClasses(t *testing.T) { name: "storage classes specified", args: &DefaultEvictorArgs{ PodProtections: PodProtections{ - Config: &PodProtectionsConfig{ - PodsWithPVC: &PodsWithPVCConfig{ - ProtectedStorageClasses: []ProtectedStorageClass{ - {Name: "sc1"}, - {Name: "sc2"}, - }, - }, - }, + Config: newProtectedStorageClassesConfig("sc1", "sc2"), }, }, expected: []ProtectedStorageClass{