From 3807a92df08409fe47a1a31af331e8cfd121c14b Mon Sep 17 00:00:00 2001 From: Jie Shen Date: Wed, 17 Mar 2021 17:35:21 +0800 Subject: [PATCH] Use cmp.Diff instead of diff.Object* in pkg/api --- pkg/api/persistentvolume/util_test.go | 7 +-- pkg/api/persistentvolumeclaim/util_test.go | 7 +-- pkg/api/pod/util_test.go | 59 ++++++++++----------- pkg/api/podsecuritypolicy/util_test.go | 11 ++-- pkg/api/testing/conversion_test.go | 5 +- pkg/api/testing/copy_test.go | 3 +- pkg/api/testing/defaulting_test.go | 4 +- pkg/api/testing/serialization_proto_test.go | 5 +- pkg/api/testing/serialization_test.go | 9 ++-- pkg/api/testing/unstructured_test.go | 6 +-- 10 files changed, 61 insertions(+), 55 deletions(-) diff --git a/pkg/api/persistentvolume/util_test.go b/pkg/api/persistentvolume/util_test.go index 3cea5aedd5b..f44b3235764 100644 --- a/pkg/api/persistentvolume/util_test.go +++ b/pkg/api/persistentvolume/util_test.go @@ -20,7 +20,8 @@ import ( "reflect" "testing" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" + utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" api "k8s.io/kubernetes/pkg/apis/core" @@ -83,10 +84,10 @@ func TestDropDisabledFields(t *testing.T) { DropDisabledFields(tc.newSpec, tc.oldSpec) if !reflect.DeepEqual(tc.newSpec, tc.expectNewSpec) { - t.Error(diff.ObjectReflectDiff(tc.newSpec, tc.expectNewSpec)) + t.Error(cmp.Diff(tc.newSpec, tc.expectNewSpec)) } if !reflect.DeepEqual(tc.oldSpec, tc.expectOldSpec) { - t.Error(diff.ObjectReflectDiff(tc.oldSpec, tc.expectOldSpec)) + t.Error(cmp.Diff(tc.oldSpec, tc.expectOldSpec)) } }) } diff --git a/pkg/api/persistentvolumeclaim/util_test.go b/pkg/api/persistentvolumeclaim/util_test.go index 0a23cdbc6c5..a8ea213dd67 100644 --- a/pkg/api/persistentvolumeclaim/util_test.go +++ b/pkg/api/persistentvolumeclaim/util_test.go @@ -21,7 +21,8 @@ import ( "reflect" "testing" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" + utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/kubernetes/pkg/apis/core" @@ -87,12 +88,12 @@ func TestDropDisabledSnapshotDataSource(t *testing.T) { // old pvc should never be changed if !reflect.DeepEqual(oldpvc, oldpvcInfo.pvc()) { - t.Errorf("old pvc changed: %v", diff.ObjectReflectDiff(oldpvc, oldpvcInfo.pvc())) + t.Errorf("old pvc changed: %v", cmp.Diff(oldpvc, oldpvcInfo.pvc())) } // new pvc should not be changed if !reflect.DeepEqual(newpvc, newpvcInfo.pvc()) { - t.Errorf("new pvc changed: %v", diff.ObjectReflectDiff(newpvc, newpvcInfo.pvc())) + t.Errorf("new pvc changed: %v", cmp.Diff(newpvc, newpvcInfo.pvc())) } }) } diff --git a/pkg/api/pod/util_test.go b/pkg/api/pod/util_test.go index 1df8f73d77a..11e254f9908 100644 --- a/pkg/api/pod/util_test.go +++ b/pkg/api/pod/util_test.go @@ -27,7 +27,6 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/validation/field" utilfeature "k8s.io/apiserver/pkg/util/feature" @@ -718,14 +717,14 @@ func TestDropSubPath(t *testing.T) { // old pod should never be changed if !reflect.DeepEqual(oldPod, oldPodInfo.pod()) { - t.Errorf("old pod changed: %v", diff.ObjectReflectDiff(oldPod, oldPodInfo.pod())) + t.Errorf("old pod changed: %v", cmp.Diff(oldPod, oldPodInfo.pod())) } switch { case enabled || oldPodHasSubpaths: // new pod should not be changed if the feature is enabled, or if the old pod had subpaths if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } case newPodHasSubpaths: // new pod should be changed @@ -734,12 +733,12 @@ func TestDropSubPath(t *testing.T) { } // new pod should not have subpaths if !reflect.DeepEqual(newPod, podWithoutSubpaths()) { - t.Errorf("new pod had subpaths: %v", diff.ObjectReflectDiff(newPod, podWithoutSubpaths())) + t.Errorf("new pod had subpaths: %v", cmp.Diff(newPod, podWithoutSubpaths())) } default: // new pod should not need to be changed if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } } }) @@ -826,14 +825,14 @@ func TestDropProcMount(t *testing.T) { // old pod should never be changed if !reflect.DeepEqual(oldPod, oldPodInfo.pod()) { - t.Errorf("old pod changed: %v", diff.ObjectReflectDiff(oldPod, oldPodInfo.pod())) + t.Errorf("old pod changed: %v", cmp.Diff(oldPod, oldPodInfo.pod())) } switch { case enabled || oldPodHasProcMount: // new pod should not be changed if the feature is enabled, or if the old pod had ProcMount if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } case newPodHasProcMount: // new pod should be changed @@ -847,7 +846,7 @@ func TestDropProcMount(t *testing.T) { default: // new pod should not need to be changed if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } } }) @@ -936,14 +935,14 @@ func TestDropEmptyDirSizeLimit(t *testing.T) { // old pod should never be changed if !reflect.DeepEqual(oldPod, oldPodInfo.pod()) { - t.Errorf("old pod changed: %v", diff.ObjectReflectDiff(oldPod, oldPodInfo.pod())) + t.Errorf("old pod changed: %v", cmp.Diff(oldPod, oldPodInfo.pod())) } switch { case enabled || oldPodHasEmptyDirSizeLimit: // new pod should not be changed if the feature is enabled, or if the old pod had EmptyDir SizeLimit if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } case newPodHasEmptyDirSizeLimit: // new pod should be changed @@ -952,12 +951,12 @@ func TestDropEmptyDirSizeLimit(t *testing.T) { } // new pod should not have EmptyDir SizeLimit if !reflect.DeepEqual(newPod, podWithoutEmptyDirSizeLimit()) { - t.Errorf("new pod had EmptyDir SizeLimit: %v", diff.ObjectReflectDiff(newPod, podWithoutEmptyDirSizeLimit())) + t.Errorf("new pod had EmptyDir SizeLimit: %v", cmp.Diff(newPod, podWithoutEmptyDirSizeLimit())) } default: // new pod should not need to be changed if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } } }) @@ -1018,14 +1017,14 @@ func TestDropAppArmor(t *testing.T) { // old pod should never be changed if !reflect.DeepEqual(oldPod, oldPodInfo.pod()) { - t.Errorf("old pod changed: %v", diff.ObjectReflectDiff(oldPod, oldPodInfo.pod())) + t.Errorf("old pod changed: %v", cmp.Diff(oldPod, oldPodInfo.pod())) } switch { case enabled || oldPodHasAppArmor: // new pod should not be changed if the feature is enabled, or if the old pod had AppArmor if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } case newPodHasAppArmor: // new pod should be changed @@ -1034,12 +1033,12 @@ func TestDropAppArmor(t *testing.T) { } // new pod should not have AppArmor if !reflect.DeepEqual(newPod, podWithoutAppArmor()) { - t.Errorf("new pod had EmptyDir SizeLimit: %v", diff.ObjectReflectDiff(newPod, podWithoutAppArmor())) + t.Errorf("new pod had EmptyDir SizeLimit: %v", cmp.Diff(newPod, podWithoutAppArmor())) } default: // new pod should not need to be changed if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } } }) @@ -1111,14 +1110,14 @@ func TestDropSubPathExpr(t *testing.T) { // old pod should never be changed if !reflect.DeepEqual(oldPod, oldPodInfo.pod()) { - t.Errorf("old pod changed: %v", diff.ObjectReflectDiff(oldPod, oldPodInfo.pod())) + t.Errorf("old pod changed: %v", cmp.Diff(oldPod, oldPodInfo.pod())) } switch { case enabled || oldPodHasSubpaths: // new pod should not be changed if the feature is enabled, or if the old pod had subpaths if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } case newPodHasSubpaths: // new pod should be changed @@ -1127,12 +1126,12 @@ func TestDropSubPathExpr(t *testing.T) { } // new pod should not have subpaths if !reflect.DeepEqual(newPod, podWithoutSubpaths()) { - t.Errorf("new pod had subpaths: %v", diff.ObjectReflectDiff(newPod, podWithoutSubpaths())) + t.Errorf("new pod had subpaths: %v", cmp.Diff(newPod, podWithoutSubpaths())) } default: // new pod should not need to be changed if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } } }) @@ -1208,14 +1207,14 @@ func TestDropProbeGracePeriod(t *testing.T) { // old pod should never be changed if !reflect.DeepEqual(oldPod, oldPodInfo.pod()) { - t.Errorf("old pod changed: %v", diff.ObjectReflectDiff(oldPod, oldPodInfo.pod())) + t.Errorf("old pod changed: %v", cmp.Diff(oldPod, oldPodInfo.pod())) } switch { case enabled || oldPodHasGracePeriod: // new pod should not be changed if the feature is enabled, or if the old pod had subpaths if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } case newPodHasGracePeriod: // new pod should be changed @@ -1224,12 +1223,12 @@ func TestDropProbeGracePeriod(t *testing.T) { } // new pod should not have subpaths if !reflect.DeepEqual(newPod, podWithoutProbeGracePeriod()) { - t.Errorf("new pod had probe-level terminationGracePeriod: %v", diff.ObjectReflectDiff(newPod, podWithoutProbeGracePeriod())) + t.Errorf("new pod had probe-level terminationGracePeriod: %v", cmp.Diff(newPod, podWithoutProbeGracePeriod())) } default: // new pod should not need to be changed if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } } }) @@ -1328,11 +1327,11 @@ func TestDropStatusPodIPs(t *testing.T) { old := tc.oldPodStatus.DeepCopy() // old pod status should never be changed if !reflect.DeepEqual(tc.oldPodStatus, old) { - t.Errorf("%v: old pod status changed: %v", tc.name, diff.ObjectReflectDiff(tc.oldPodStatus, old)) + t.Errorf("%v: old pod status changed: %v", tc.name, cmp.Diff(tc.oldPodStatus, old)) } if !reflect.DeepEqual(tc.podStatus, tc.comparePodStatus) { - t.Errorf("%v: unexpected pod status: %v", tc.name, diff.ObjectReflectDiff(tc.podStatus, tc.comparePodStatus)) + t.Errorf("%v: unexpected pod status: %v", tc.name, cmp.Diff(tc.podStatus, tc.comparePodStatus)) } }() } @@ -1397,14 +1396,14 @@ func TestDropEphemeralContainers(t *testing.T) { // old pod should never be changed if !reflect.DeepEqual(oldPod, oldPodInfo.pod()) { - t.Errorf("old pod changed: %v", diff.ObjectReflectDiff(oldPod, oldPodInfo.pod())) + t.Errorf("old pod changed: %v", cmp.Diff(oldPod, oldPodInfo.pod())) } switch { case enabled || oldPodHasEphemeralContainers: // new pod should not be changed if the feature is enabled, or if the old pod had subpaths if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } case newPodHasEphemeralContainers: // new pod should be changed @@ -1413,12 +1412,12 @@ func TestDropEphemeralContainers(t *testing.T) { } // new pod should not have subpaths if !reflect.DeepEqual(newPod, podWithoutEphemeralContainers()) { - t.Errorf("new pod had subpaths: %v", diff.ObjectReflectDiff(newPod, podWithoutEphemeralContainers())) + t.Errorf("new pod had subpaths: %v", cmp.Diff(newPod, podWithoutEphemeralContainers())) } default: // new pod should not need to be changed if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } } }) diff --git a/pkg/api/podsecuritypolicy/util_test.go b/pkg/api/podsecuritypolicy/util_test.go index 1535b04128c..7b86b669e59 100644 --- a/pkg/api/podsecuritypolicy/util_test.go +++ b/pkg/api/podsecuritypolicy/util_test.go @@ -21,7 +21,8 @@ import ( "reflect" "testing" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" + utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" api "k8s.io/kubernetes/pkg/apis/core" @@ -78,14 +79,14 @@ func TestDropAllowedProcMountTypes(t *testing.T) { // old PodSecurityPolicySpec should never be changed if !reflect.DeepEqual(oldPSPSpec, oldPSPSpecInfo.sc()) { - t.Errorf("old PodSecurityPolicySpec changed: %v", diff.ObjectReflectDiff(oldPSPSpec, oldPSPSpecInfo.sc())) + t.Errorf("old PodSecurityPolicySpec changed: %v", cmp.Diff(oldPSPSpec, oldPSPSpecInfo.sc())) } switch { case enabled || oldPSPSpecHasAllowedProcMountTypes: // new PodSecurityPolicySpec should not be changed if the feature is enabled, or if the old PodSecurityPolicySpec had AllowedProcMountTypes if !reflect.DeepEqual(newPSPSpec, newPSPSpecInfo.sc()) { - t.Errorf("new PodSecurityPolicySpec changed: %v", diff.ObjectReflectDiff(newPSPSpec, newPSPSpecInfo.sc())) + t.Errorf("new PodSecurityPolicySpec changed: %v", cmp.Diff(newPSPSpec, newPSPSpecInfo.sc())) } case newPSPSpecHasAllowedProcMountTypes: // new PodSecurityPolicySpec should be changed @@ -94,12 +95,12 @@ func TestDropAllowedProcMountTypes(t *testing.T) { } // new PodSecurityPolicySpec should not have AllowedProcMountTypes if !reflect.DeepEqual(newPSPSpec, scWithoutAllowedProcMountTypes()) { - t.Errorf("new PodSecurityPolicySpec had PodSecurityPolicySpecAllowedProcMountTypes: %v", diff.ObjectReflectDiff(newPSPSpec, scWithoutAllowedProcMountTypes())) + t.Errorf("new PodSecurityPolicySpec had PodSecurityPolicySpecAllowedProcMountTypes: %v", cmp.Diff(newPSPSpec, scWithoutAllowedProcMountTypes())) } default: // new PodSecurityPolicySpec should not need to be changed if !reflect.DeepEqual(newPSPSpec, newPSPSpecInfo.sc()) { - t.Errorf("new PodSecurityPolicySpec changed: %v", diff.ObjectReflectDiff(newPSPSpec, newPSPSpecInfo.sc())) + t.Errorf("new PodSecurityPolicySpec changed: %v", cmp.Diff(newPSPSpec, newPSPSpecInfo.sc())) } } }) diff --git a/pkg/api/testing/conversion_test.go b/pkg/api/testing/conversion_test.go index 6dd3408cf54..3fea8c005df 100644 --- a/pkg/api/testing/conversion_test.go +++ b/pkg/api/testing/conversion_test.go @@ -21,12 +21,13 @@ import ( "math/rand" "testing" + "github.com/google/go-cmp/cmp" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api/legacyscheme" api "k8s.io/kubernetes/pkg/apis/core" ) @@ -83,7 +84,7 @@ func BenchmarkNodeConversion(b *testing.B) { } b.StopTimer() if !apiequality.Semantic.DeepDerivative(node, *result) { - b.Fatalf("Incorrect conversion: %s", diff.ObjectDiff(node, *result)) + b.Fatalf("Incorrect conversion: %s", cmp.Diff(node, *result)) } } diff --git a/pkg/api/testing/copy_test.go b/pkg/api/testing/copy_test.go index fd032cfd06f..1169714e977 100644 --- a/pkg/api/testing/copy_test.go +++ b/pkg/api/testing/copy_test.go @@ -22,6 +22,7 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" "github.com/google/gofuzz" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" @@ -51,7 +52,7 @@ func doDeepCopyTest(t *testing.T, kind schema.GroupVersionKind, f *fuzz.Fuzzer) f.Fuzz(item) itemCopy := item.DeepCopyObject() if !reflect.DeepEqual(item, itemCopy) { - t.Errorf("\nexpected: %#v\n\ngot: %#v\n\ndiff: %v", item, itemCopy, diff.ObjectReflectDiff(item, itemCopy)) + t.Errorf("\nexpected: %#v\n\ngot: %#v\n\ndiff: %v", item, itemCopy, cmp.Diff(item, itemCopy)) } prefuzzData := &bytes.Buffer{} diff --git a/pkg/api/testing/defaulting_test.go b/pkg/api/testing/defaulting_test.go index d041046d05e..b6b0533cdbb 100644 --- a/pkg/api/testing/defaulting_test.go +++ b/pkg/api/testing/defaulting_test.go @@ -22,6 +22,7 @@ import ( "sort" "testing" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" apiv1 "k8s.io/api/core/v1" @@ -30,7 +31,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api/legacyscheme" ) @@ -235,7 +235,7 @@ func TestDefaulting(t *testing.T) { if !reflect.DeepEqual(original, withDefaults) { changedOnce = true if !expectedChanged { - t.Errorf("{Group: \"%s\", Version: \"%s\", Kind: \"%s\"} did not expect defaults to be set - update expected or check defaulter registering: %s", gvk.Group, gvk.Version, gvk.Kind, diff.ObjectReflectDiff(original, withDefaults)) + t.Errorf("{Group: \"%s\", Version: \"%s\", Kind: \"%s\"} did not expect defaults to be set - update expected or check defaulter registering: %s", gvk.Group, gvk.Version, gvk.Kind, cmp.Diff(original, withDefaults)) } } } diff --git a/pkg/api/testing/serialization_proto_test.go b/pkg/api/testing/serialization_proto_test.go index 9e90b3fc15a..30f02eddd96 100644 --- a/pkg/api/testing/serialization_proto_test.go +++ b/pkg/api/testing/serialization_proto_test.go @@ -25,6 +25,8 @@ import ( "testing" "github.com/gogo/protobuf/proto" + "github.com/google/go-cmp/cmp" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" apiequality "k8s.io/apimachinery/pkg/api/equality" @@ -32,7 +34,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer/protobuf" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api/legacyscheme" api "k8s.io/kubernetes/pkg/apis/core" _ "k8s.io/kubernetes/pkg/apis/extensions" @@ -112,7 +113,7 @@ func TestProtobufRoundTrip(t *testing.T) { } if !apiequality.Semantic.Equalities.DeepEqual(out, obj) { t.Logf("marshal\n%s", hex.Dump(data)) - t.Fatalf("Unmarshal is unequal\n%s", diff.ObjectGoPrintDiff(out, obj)) + t.Fatalf("Unmarshal is unequal\n%s", cmp.Diff(out, obj)) } } diff --git a/pkg/api/testing/serialization_test.go b/pkg/api/testing/serialization_test.go index e36989ef0fa..f5c725998db 100644 --- a/pkg/api/testing/serialization_test.go +++ b/pkg/api/testing/serialization_test.go @@ -25,7 +25,9 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" jsoniter "github.com/json-iterator/go" + appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" @@ -38,7 +40,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer/json" "k8s.io/apimachinery/pkg/runtime/serializer/streaming" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/watch" "k8s.io/kubernetes/pkg/api/legacyscheme" @@ -254,7 +255,7 @@ func TestEncodePtr(t *testing.T) { t.Fatalf("Got wrong type") } if !apiequality.Semantic.DeepEqual(obj2, pod) { - t.Errorf("\nExpected:\n\n %#v,\n\nGot:\n\n %#vDiff: %v\n\n", pod, obj2, diff.ObjectDiff(obj2, pod)) + t.Errorf("\nExpected:\n\n %#v,\n\nGot:\n\n %#vDiff: %v\n\n", pod, obj2, cmp.Diff(obj2, pod)) } } @@ -373,7 +374,7 @@ func TestObjectWatchFraming(t *testing.T) { resultSecret.Kind = "Secret" resultSecret.APIVersion = "v1" if !apiequality.Semantic.DeepEqual(v1secret, res) { - t.Fatalf("objects did not match: %s", diff.ObjectGoPrintDiff(v1secret, res)) + t.Fatalf("objects did not match: %s", cmp.Diff(v1secret, res)) } // write a watch event through the frame writer and read it back in @@ -407,7 +408,7 @@ func TestObjectWatchFraming(t *testing.T) { } if !apiequality.Semantic.DeepEqual(secret, outEvent.Object.Object) { - t.Fatalf("%s: did not match after frame decoding: %s", info.MediaType, diff.ObjectGoPrintDiff(secret, outEvent.Object.Object)) + t.Fatalf("%s: did not match after frame decoding: %s", info.MediaType, cmp.Diff(secret, outEvent.Object.Object)) } } } diff --git a/pkg/api/testing/unstructured_test.go b/pkg/api/testing/unstructured_test.go index 32d51183402..21c6373056c 100644 --- a/pkg/api/testing/unstructured_test.go +++ b/pkg/api/testing/unstructured_test.go @@ -22,6 +22,7 @@ import ( "sort" "testing" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" jsoniter "github.com/json-iterator/go" @@ -33,7 +34,6 @@ import ( metaunstruct "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/json" "k8s.io/kubernetes/pkg/api/legacyscheme" api "k8s.io/kubernetes/pkg/apis/core" @@ -96,7 +96,7 @@ func doRoundTrip(t *testing.T, internalVersion schema.GroupVersion, externalVers return } if !apiequality.Semantic.DeepEqual(item, unmarshalledObj) { - t.Errorf("Object changed during JSON operations, diff: %v", diff.ObjectReflectDiff(item, unmarshalledObj)) + t.Errorf("Object changed during JSON operations, diff: %v", cmp.Diff(item, unmarshalledObj)) return } @@ -114,7 +114,7 @@ func doRoundTrip(t *testing.T, internalVersion schema.GroupVersion, externalVers } if !apiequality.Semantic.DeepEqual(item, newObj) { - t.Errorf("Object changed, diff: %v", diff.ObjectReflectDiff(item, newObj)) + t.Errorf("Object changed, diff: %v", cmp.Diff(item, newObj)) } }