From 8808b718c9aacf6ff1730f1e15e2af6e97054034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Tyczy=C5=84ski?= Date: Mon, 21 Nov 2022 12:03:54 +0100 Subject: [PATCH] Explicit sorting in TestList storage test Kubernetes-commit: 34de5fa73dabd9dcbd6f535cf6a853371ec653f1 --- pkg/storage/testing/store_tests.go | 3 +++ pkg/storage/testing/utils.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/storage/testing/store_tests.go b/pkg/storage/testing/store_tests.go index c60265308..75d17ecac 100644 --- a/pkg/storage/testing/store_tests.go +++ b/pkg/storage/testing/store_tests.go @@ -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 diff --git a/pkg/storage/testing/utils.go b/pkg/storage/testing/utils.go index 3532ccea5..7d94355a0 100644 --- a/pkg/storage/testing/utils.go +++ b/pkg/storage/testing/utils.go @@ -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] +}