mirror of https://github.com/k3s-io/k3s
Do not use DeepEqual to compare slices in test.
This wraps DeepEqual with a helper that considers nil slices and empty slices to be equal. Scheduler code might use a nil slice or empty slice to represent an empty list, so tests should not be sensitive to the difference. Tests could fail because DeepEqual considers nil to be different from an empty slice.pull/8/head
parent
10b8665a1c
commit
2de996856f
|
@ -378,6 +378,14 @@ func TestUpdateResult(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// slicesEqual wraps reflect.DeepEqual, but returns true when comparing nil and empty slice.
|
||||
func slicesEqual(a, b []algorithm.PredicateFailureReason) bool {
|
||||
if len(a) == 0 && len(b) == 0 {
|
||||
return true
|
||||
}
|
||||
return reflect.DeepEqual(a, b)
|
||||
}
|
||||
|
||||
func TestLookupResult(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -504,9 +512,9 @@ func TestLookupResult(t *testing.T) {
|
|||
if fit != test.expectedPredicateItem.fit {
|
||||
t.Errorf("Failed: %s, expected fit: %v, but got: %v", test.name, test.cachedItem.fit, fit)
|
||||
}
|
||||
if !reflect.DeepEqual(reasons, test.expectedPredicateItem.reasons) {
|
||||
if !slicesEqual(reasons, test.expectedPredicateItem.reasons) {
|
||||
t.Errorf("Failed: %s, expected reasons: %v, but got: %v",
|
||||
test.name, test.cachedItem.reasons, reasons)
|
||||
test.name, test.expectedPredicateItem.reasons, reasons)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue