mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 16:29:21 +00:00
kubelet_test: Fix verifyStringArrayEqualsAnyOrder().
Old implementation can not tell cases where strings are repetitive. e.g. {"a", "b", "b"} and {"a", "a", "b"} will be treated as correct.
This commit is contained in:
parent
aa2e7fe688
commit
e6820bd0ca
@ -27,6 +27,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -143,23 +144,15 @@ func verifyStringArrayEquals(t *testing.T, actual, expected []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func verifyStringArrayEqualsAnyOrder(t *testing.T, actual, expected []string) {
|
func verifyStringArrayEqualsAnyOrder(t *testing.T, actual, expected []string) {
|
||||||
invalid := len(actual) != len(expected)
|
var act, exp []string
|
||||||
if !invalid {
|
copy(act, actual)
|
||||||
for _, exp := range expected {
|
copy(exp, expected)
|
||||||
found := false
|
|
||||||
for _, act := range actual {
|
sort.StringSlice(act).Sort()
|
||||||
if exp == act {
|
sort.StringSlice(exp).Sort()
|
||||||
found = true
|
|
||||||
break
|
if !reflect.DeepEqual(exp, act) {
|
||||||
}
|
t.Errorf("Expected(sorted): %#v, Actual(sorted): %#v", exp, act)
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
t.Errorf("Expected element %q not found in %#v", exp, actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if invalid {
|
|
||||||
t.Errorf("Expected: %#v, Actual: %#v", expected, actual)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user