Remove copies of ObjectDiff function
This commit is contained in:
parent
9b3ca2fb0d
commit
a4597c2d60
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package conversion
|
package conversion
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -522,7 +521,7 @@ func TestConverter_fuzz(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if e, a := item.from, item.check; !reflect.DeepEqual(e, a) {
|
if e, a := item.from, item.check; !reflect.DeepEqual(e, a) {
|
||||||
t.Errorf("(%v, %v): unexpected diff: %v", i, j, objDiff(e, a))
|
t.Errorf("(%v, %v): unexpected diff: %v", i, j, diff.ObjectDiff(e, a))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -570,7 +569,7 @@ func TestConverter_MapElemAddr(t *testing.T) {
|
|||||||
third := Foo{}
|
third := Foo{}
|
||||||
err = c.Convert(&second, &third, AllowDifferentFieldTypeNames, nil)
|
err = c.Convert(&second, &third, AllowDifferentFieldTypeNames, nil)
|
||||||
if e, a := first, third; !reflect.DeepEqual(e, a) {
|
if e, a := first, third; !reflect.DeepEqual(e, a) {
|
||||||
t.Errorf("Unexpected diff: %v", objDiff(e, a))
|
t.Errorf("Unexpected diff: %v", diff.ObjectDiff(e, a))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,27 +820,7 @@ func TestConverter_FieldRename(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if e, a := item.expect, item.to; !reflect.DeepEqual(e, a) {
|
if e, a := item.expect, item.to; !reflect.DeepEqual(e, a) {
|
||||||
t.Errorf("%v: unexpected diff: %v", name, objDiff(e, a))
|
t.Errorf("%v: unexpected diff: %v", name, diff.ObjectDiff(e, a))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func objDiff(a, b interface{}) string {
|
|
||||||
ab, err := json.Marshal(a)
|
|
||||||
if err != nil {
|
|
||||||
panic("a")
|
|
||||||
}
|
|
||||||
bb, err := json.Marshal(b)
|
|
||||||
if err != nil {
|
|
||||||
panic("b")
|
|
||||||
}
|
|
||||||
return diff.StringDiff(string(ab), string(bb))
|
|
||||||
|
|
||||||
// An alternate diff attempt, in case json isn't showing you
|
|
||||||
// the difference. (reflect.DeepEqual makes a distinction between
|
|
||||||
// nil and empty slices, for example.)
|
|
||||||
//return diff.StringDiff(
|
|
||||||
// fmt.Sprintf("%#v", a),
|
|
||||||
// fmt.Sprintf("%#v", b),
|
|
||||||
//)
|
|
||||||
}
|
|
||||||
|
@ -178,26 +178,6 @@ func GetTestScheme() (*runtime.Scheme, runtime.Codec) {
|
|||||||
return s, codec
|
return s, codec
|
||||||
}
|
}
|
||||||
|
|
||||||
func objDiff(a, b interface{}) string {
|
|
||||||
ab, err := json.Marshal(a)
|
|
||||||
if err != nil {
|
|
||||||
panic("a")
|
|
||||||
}
|
|
||||||
bb, err := json.Marshal(b)
|
|
||||||
if err != nil {
|
|
||||||
panic("b")
|
|
||||||
}
|
|
||||||
return diff.StringDiff(string(ab), string(bb))
|
|
||||||
|
|
||||||
// An alternate diff attempt, in case json isn't showing you
|
|
||||||
// the difference. (reflect.DeepEqual makes a distinction between
|
|
||||||
// nil and empty slices, for example.)
|
|
||||||
//return diff.StringDiff(
|
|
||||||
// fmt.Sprintf("%#v", a),
|
|
||||||
// fmt.Sprintf("%#v", b),
|
|
||||||
//)
|
|
||||||
}
|
|
||||||
|
|
||||||
var semantic = conversion.EqualitiesOrDie(
|
var semantic = conversion.EqualitiesOrDie(
|
||||||
func(a, b MyWeirdCustomEmbeddedVersionKindField) bool {
|
func(a, b MyWeirdCustomEmbeddedVersionKindField) bool {
|
||||||
a.APIVersion, a.ObjectKind = "", ""
|
a.APIVersion, a.ObjectKind = "", ""
|
||||||
@ -231,7 +211,7 @@ func runTest(t *testing.T, source interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !semantic.DeepEqual(source, obj3) {
|
if !semantic.DeepEqual(source, obj3) {
|
||||||
t.Errorf("3: %v: diff: %v", name, objDiff(source, obj3))
|
t.Errorf("3: %v: diff: %v", name, diff.ObjectDiff(source, obj3))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user