Skip to content

Commit b84b262

Browse files
authored
Merge pull request #1722 from ingvagabund/minor-refactoring
Test code refactorings
2 parents bf6a51f + d0548b7 commit b84b262

File tree

2 files changed

+53
-117
lines changed

2 files changed

+53
-117
lines changed

pkg/descheduler/pod/pods_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ func TestListPodsOnANode(t *testing.T) {
117117
}
118118
}
119119

120+
func getPodListNames(pods []*v1.Pod) []string {
121+
names := []string{}
122+
for _, pod := range pods {
123+
names = append(names, pod.Name)
124+
}
125+
return names
126+
}
127+
120128
func TestSortPodsBasedOnPriorityLowToHigh(t *testing.T) {
121129
n1 := test.BuildTestNode("n1", 4000, 3000, 9, nil)
122130

@@ -150,10 +158,11 @@ func TestSortPodsBasedOnPriorityLowToHigh(t *testing.T) {
150158
p6.Spec.Priority = nil
151159

152160
podList := []*v1.Pod{p4, p3, p2, p1, p6, p5}
161+
expectedPodList := []*v1.Pod{p5, p6, p1, p2, p3, p4}
153162

154163
SortPodsBasedOnPriorityLowToHigh(podList)
155-
if !reflect.DeepEqual(podList[len(podList)-1], p4) {
156-
t.Errorf("Expected last pod in sorted list to be %v which of highest priority and guaranteed but got %v", p4, podList[len(podList)-1])
164+
if !reflect.DeepEqual(getPodListNames(podList), getPodListNames(expectedPodList)) {
165+
t.Errorf("Pods were sorted in an unexpected order: %v, expected %v", getPodListNames(podList), getPodListNames(expectedPodList))
157166
}
158167
}
159168

0 commit comments

Comments
 (0)