From a4597c2d60cf98cbfe50900c1738510ca53280cb Mon Sep 17 00:00:00 2001 From: Ivan Shvedunov Date: Fri, 14 Oct 2016 01:18:00 +0300 Subject: [PATCH] Remove copies of ObjectDiff function --- pkg/conversion/converter_test.go | 27 +++------------------------ pkg/runtime/serializer/codec_test.go | 22 +--------------------- 2 files changed, 4 insertions(+), 45 deletions(-) diff --git a/pkg/conversion/converter_test.go b/pkg/conversion/converter_test.go index 47ea9f1c91d..328c2a46867 100644 --- a/pkg/conversion/converter_test.go +++ b/pkg/conversion/converter_test.go @@ -17,7 +17,6 @@ limitations under the License. package conversion import ( - "encoding/json" "fmt" "reflect" "strconv" @@ -522,7 +521,7 @@ func TestConverter_fuzz(t *testing.T) { continue } 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{} err = c.Convert(&second, &third, AllowDifferentFieldTypeNames, nil) 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 } 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), - //) -} diff --git a/pkg/runtime/serializer/codec_test.go b/pkg/runtime/serializer/codec_test.go index 87158a0c23e..678faa1a6cb 100644 --- a/pkg/runtime/serializer/codec_test.go +++ b/pkg/runtime/serializer/codec_test.go @@ -178,26 +178,6 @@ func GetTestScheme() (*runtime.Scheme, runtime.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( func(a, b MyWeirdCustomEmbeddedVersionKindField) bool { a.APIVersion, a.ObjectKind = "", "" @@ -231,7 +211,7 @@ func runTest(t *testing.T, source interface{}) { return } 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 } }