Simplify the integration test by removing the struct of nodeConfig

Signed-off-by: Dave Chen <dave.chen@arm.com>
This commit is contained in:
Dave Chen 2021-10-12 17:46:38 +08:00
parent d9896a23bc
commit 1500a5ca80

View File

@ -1072,14 +1072,9 @@ func TestPDBInPreemption(t *testing.T) {
v1.ResourceMemory: "500", v1.ResourceMemory: "500",
} }
type nodeConfig struct {
name string
res map[v1.ResourceName]string
}
tests := []struct { tests := []struct {
name string name string
nodes []*nodeConfig nodeCnt int
pdbs []*policy.PodDisruptionBudget pdbs []*policy.PodDisruptionBudget
pdbPodNum []int32 pdbPodNum []int32
existingPods []*v1.Pod existingPods []*v1.Pod
@ -1088,7 +1083,7 @@ func TestPDBInPreemption(t *testing.T) {
}{ }{
{ {
name: "A non-PDB violating pod is preempted despite its higher priority", name: "A non-PDB violating pod is preempted despite its higher priority",
nodes: []*nodeConfig{{name: "node-1", res: defaultNodeRes}}, nodeCnt: 1,
pdbs: []*policy.PodDisruptionBudget{ pdbs: []*policy.PodDisruptionBudget{
mkMinAvailablePDB("pdb-1", testCtx.NS.Name, types.UID("pdb-1-uid"), 2, map[string]string{"foo": "bar"}), mkMinAvailablePDB("pdb-1", testCtx.NS.Name, types.UID("pdb-1-uid"), 2, map[string]string{"foo": "bar"}),
}, },
@ -1128,10 +1123,7 @@ func TestPDBInPreemption(t *testing.T) {
}, },
{ {
name: "A node without any PDB violating pods is preferred for preemption", name: "A node without any PDB violating pods is preferred for preemption",
nodes: []*nodeConfig{ nodeCnt: 2,
{name: "node-1", res: defaultNodeRes},
{name: "node-2", res: defaultNodeRes},
},
pdbs: []*policy.PodDisruptionBudget{ pdbs: []*policy.PodDisruptionBudget{
mkMinAvailablePDB("pdb-1", testCtx.NS.Name, types.UID("pdb-1-uid"), 2, map[string]string{"foo": "bar"}), mkMinAvailablePDB("pdb-1", testCtx.NS.Name, types.UID("pdb-1-uid"), 2, map[string]string{"foo": "bar"}),
}, },
@ -1166,11 +1158,7 @@ func TestPDBInPreemption(t *testing.T) {
}, },
{ {
name: "A node with fewer PDB violating pods is preferred for preemption", name: "A node with fewer PDB violating pods is preferred for preemption",
nodes: []*nodeConfig{ nodeCnt: 3,
{name: "node-1", res: defaultNodeRes},
{name: "node-2", res: defaultNodeRes},
{name: "node-3", res: defaultNodeRes},
},
pdbs: []*policy.PodDisruptionBudget{ pdbs: []*policy.PodDisruptionBudget{
mkMinAvailablePDB("pdb-1", testCtx.NS.Name, types.UID("pdb-1-uid"), 2, map[string]string{"foo1": "bar"}), mkMinAvailablePDB("pdb-1", testCtx.NS.Name, types.UID("pdb-1-uid"), 2, map[string]string{"foo1": "bar"}),
mkMinAvailablePDB("pdb-2", testCtx.NS.Name, types.UID("pdb-2-uid"), 2, map[string]string{"foo2": "bar"}), mkMinAvailablePDB("pdb-2", testCtx.NS.Name, types.UID("pdb-2-uid"), 2, map[string]string{"foo2": "bar"}),
@ -1249,10 +1237,11 @@ func TestPDBInPreemption(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
for _, nodeConf := range test.nodes { for i := 1; i <= test.nodeCnt; i++ {
_, err := createNode(cs, st.MakeNode().Name(nodeConf.name).Capacity(nodeConf.res).Obj()) nodeName := fmt.Sprintf("node-%v", i)
_, err := createNode(cs, st.MakeNode().Name(nodeName).Capacity(defaultNodeRes).Obj())
if err != nil { if err != nil {
t.Fatalf("Error creating node %v: %v", nodeConf.name, err) t.Fatalf("Error creating node %v: %v", nodeName, err)
} }
} }