Explicit sorting in TestList storage test

Kubernetes-commit: 34de5fa73dabd9dcbd6f535cf6a853371ec653f1
This commit is contained in:
Wojciech Tyczyński 2022-11-21 12:03:54 +01:00 committed by Kubernetes Publisher
parent 299c158ba3
commit 8808b718c9
2 changed files with 17 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import (
"fmt"
"math"
"reflect"
"sort"
"strconv"
"strings"
"sync"
@ -1055,11 +1056,13 @@ func RunTestList(ctx context.Context, t *testing.T, store storage.Interface, ign
}
if tt.expectedAlternatives == nil {
sort.Sort(sortablePodList(tt.expectedOut))
ExpectNoDiff(t, "incorrect list pods", tt.expectedOut, out.Items)
} else {
toInterfaceSlice := func(podLists [][]example.Pod) []interface{} {
result := make([]interface{}, 0, len(podLists))
for i := range podLists {
sort.Sort(sortablePodList(podLists[i]))
result = append(result, podLists[i])
}
return result

View File

@ -291,3 +291,17 @@ func (ft *failingTransformer) TransformFromStorage(ctx context.Context, data []b
func (ft *failingTransformer) TransformToStorage(ctx context.Context, data []byte, dataCtx value.Context) ([]byte, error) {
return data, nil
}
type sortablePodList []example.Pod
func (s sortablePodList) Len() int {
return len(s)
}
func (s sortablePodList) Less(i, j int) bool {
return computePodKey(&s[i]) < computePodKey(&s[j])
}
func (s sortablePodList) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}