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.
pull/6/head
Yifan Gu 2015-03-26 15:14:02 -07:00
parent aa2e7fe688
commit e6820bd0ca
1 changed files with 10 additions and 17 deletions

View File

@ -27,6 +27,7 @@ import (
"path"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
"sync"
@ -143,23 +144,15 @@ func verifyStringArrayEquals(t *testing.T, actual, expected []string) {
}
func verifyStringArrayEqualsAnyOrder(t *testing.T, actual, expected []string) {
invalid := len(actual) != len(expected)
if !invalid {
for _, exp := range expected {
found := false
for _, act := range actual {
if exp == act {
found = true
break
}
}
if !found {
t.Errorf("Expected element %q not found in %#v", exp, actual)
}
}
}
if invalid {
t.Errorf("Expected: %#v, Actual: %#v", expected, actual)
var act, exp []string
copy(act, actual)
copy(exp, expected)
sort.StringSlice(act).Sort()
sort.StringSlice(exp).Sort()
if !reflect.DeepEqual(exp, act) {
t.Errorf("Expected(sorted): %#v, Actual(sorted): %#v", exp, act)
}
}