Explicit sorting in TestList storage test
Kubernetes-commit: 34de5fa73dabd9dcbd6f535cf6a853371ec653f1
This commit is contained in:
parent
299c158ba3
commit
8808b718c9
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue