From dab5075ee3c9050813299734d28e348e58d8c441 Mon Sep 17 00:00:00 2001 From: Nikhita Raghunath Date: Wed, 23 Aug 2017 21:58:47 +0530 Subject: [PATCH] roundtrip: fix error messages --- .../pkg/api/testing/roundtrip/roundtrip.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/api/testing/roundtrip/roundtrip.go b/staging/src/k8s.io/apimachinery/pkg/api/testing/roundtrip/roundtrip.go index 6fec930dc21..479a6a50a3e 100644 --- a/staging/src/k8s.io/apimachinery/pkg/api/testing/roundtrip/roundtrip.go +++ b/staging/src/k8s.io/apimachinery/pkg/api/testing/roundtrip/roundtrip.go @@ -270,6 +270,12 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object // deep copy the original object object = object.DeepCopyObject() name := reflect.TypeOf(object).Elem().Name() + if !apiequality.Semantic.DeepEqual(original, object) { + t.Errorf("%v: DeepCopy altered the object, diff: %v", name, diff.ObjectReflectDiff(original, object)) + t.Errorf("%s", spew.Sdump(original)) + t.Errorf("%s", spew.Sdump(object)) + return + } // catch deepcopy errors early if !apiequality.Semantic.DeepEqual(original, object) { @@ -323,7 +329,7 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object // ensure that the object produced from decoding the encoded data is equal // to the original object if !apiequality.Semantic.DeepEqual(original, obj2) { - t.Errorf("%v: diff: %v\nCodec: %#v\nSource:\n\n%#v\n\nEncoded:\n\n%s\n\nFinal:\n\n%#v", name, diff.ObjectReflectDiff(object, obj2), codec, printer.Sprintf("%#v", object), dataAsString(data), printer.Sprintf("%#v", obj2)) + t.Errorf("%v: diff: %v\nCodec: %#v\nSource:\n\n%#v\n\nEncoded:\n\n%s\n\nFinal:\n\n%#v", name, diff.ObjectReflectDiff(original, obj2), codec, printer.Sprintf("%#v", original), dataAsString(data), printer.Sprintf("%#v", obj2)) return } @@ -370,7 +376,7 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object // NOTE: we use the encoding+decoding here as an alternative, guaranteed deep-copy to compare against. fuzzer.ValueFuzz(object) if !apiequality.Semantic.DeepEqual(original, obj3) { - t.Errorf("%v: fuzzing a copy altered the original, diff: %v", name, diff.ObjectReflectDiff(original, object)) + t.Errorf("%v: fuzzing a copy altered the original, diff: %v", name, diff.ObjectReflectDiff(original, obj3)) return } }