From dfd2b95d2d98501704005310bc97b93de2a68a70 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sat, 20 Dec 2025 14:08:11 +0100 Subject: [PATCH] refactor(TestDefaultEvictor): add setNodeLabel helper function --- .../defaultevictor/defaultevictor_test.go | 78 +++++-------------- 1 file changed, 18 insertions(+), 60 deletions(-) diff --git a/pkg/framework/plugins/defaultevictor/defaultevictor_test.go b/pkg/framework/plugins/defaultevictor/defaultevictor_test.go index c760b67e2..95ad9172d 100644 --- a/pkg/framework/plugins/defaultevictor/defaultevictor_test.go +++ b/pkg/framework/plugins/defaultevictor/defaultevictor_test.go @@ -87,6 +87,12 @@ func TestDefaultEvictorPreEvictionFilter(t *testing.T) { } } + setNodeLabel := func(node *v1.Node) { + node.ObjectMeta.Labels = map[string]string{ + nodeLabelKey: nodeLabelValue, + } + } + testCases := []testCase{ { description: "Pod with no tolerations running on normal node, all other nodes tainted", @@ -129,16 +135,8 @@ func TestDefaultEvictorPreEvictionFilter(t *testing.T) { }), }, nodes: []*v1.Node{ - buildTestNode("node2", func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), - buildTestNode("node3", func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), + buildTestNode("node2", setNodeLabel), + buildTestNode("node3", setNodeLabel), }, nodeFit: true, }, { @@ -152,16 +150,8 @@ func TestDefaultEvictorPreEvictionFilter(t *testing.T) { }), }, nodes: []*v1.Node{ - buildTestNode("node2", func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), - buildTestNode("node3", func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), + buildTestNode("node2", setNodeLabel), + buildTestNode("node3", setNodeLabel), }, nodeFit: true, result: true, @@ -176,16 +166,8 @@ func TestDefaultEvictorPreEvictionFilter(t *testing.T) { }), }, nodes: []*v1.Node{ - test.BuildTestNode("node2-TEST", 10, 16, 10, func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), - test.BuildTestNode("node3-TEST", 10, 16, 10, func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), + test.BuildTestNode("node2-TEST", 10, 16, 10, setNodeLabel), + test.BuildTestNode("node3-TEST", 10, 16, 10, setNodeLabel), }, nodeFit: true, }, { @@ -209,16 +191,8 @@ func TestDefaultEvictorPreEvictionFilter(t *testing.T) { }), }, nodes: []*v1.Node{ - test.BuildTestNode("node2", 100, 16, 10, func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), - test.BuildTestNode("node3", 100, 20, 10, func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), + test.BuildTestNode("node2", 100, 16, 10, setNodeLabel), + test.BuildTestNode("node3", 100, 20, 10, setNodeLabel), }, nodeFit: true, result: true, @@ -243,16 +217,8 @@ func TestDefaultEvictorPreEvictionFilter(t *testing.T) { }), }, nodes: []*v1.Node{ - test.BuildTestNode("node2", 100, 16, 10, func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), - test.BuildTestNode("node3", 100, 16, 10, func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), + test.BuildTestNode("node2", 100, 16, 10, setNodeLabel), + test.BuildTestNode("node3", 100, 16, 10, setNodeLabel), }, nodeFit: true, }, { @@ -266,16 +232,8 @@ func TestDefaultEvictorPreEvictionFilter(t *testing.T) { }), }, nodes: []*v1.Node{ - buildTestNode("node2", func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), - buildTestNode("node3", func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - nodeLabelKey: nodeLabelValue, - } - }), + buildTestNode("node2", setNodeLabel), + buildTestNode("node3", setNodeLabel), }, result: true, },