DeepEqual method seems cleaner than adding Defaulting before every

reflect.DeepEqual call
This commit is contained in:
Jerome Brette
2019-07-25 03:13:15 +00:00
parent b7405f3872
commit d783bbc0bc

View File

@@ -6,7 +6,6 @@ package target_test
import (
"encoding/base64"
"fmt"
"reflect"
"strings"
"testing"
@@ -334,12 +333,10 @@ vars:
t.Fatalf("unexpected size %d", len(vars))
}
for i := range vars[:2] {
// We have to enforce the Defaulting call in someVars[i]
// to protect from a potential call of vars[i].ObjRef.GVK()
// By using Var.DeepEqual, we are protecting the code
// from a potential invocation of vars[i].ObjRef.GVK()
// during AccumulateTarget
vars[i].Defaulting()
someVars[i].Defaulting()
if !reflect.DeepEqual(vars[i], someVars[i]) {
if !vars[i].DeepEqual(someVars[i]) {
t.Fatalf("unexpected var[%d]:\n %v\n %v", i, vars[i], someVars[i])
}
}
@@ -392,9 +389,10 @@ resources:
t.Fatalf("expected 4 vars, got %d", len(vars))
}
for i := range vars {
vars[i].Defaulting()
someVars[i].Defaulting()
if !reflect.DeepEqual(vars[i], someVars[i]) {
// By using Var.DeepEqual, we are protecting the code
// from a potential invocation of vars[i].ObjRef.GVK()
// during AccumulateTarget
if !vars[i].DeepEqual(someVars[i]) {
t.Fatalf("unexpected var[%d]:\n %v\n %v", i, vars[i], someVars[i])
}
}