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:
Yifan Gu 2015-03-26 15:14:02 -07:00
parent aa2e7fe688
commit e6820bd0ca

View File

@ -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)
} }
} }