From 12553015e229d4519edbae24d9ea16048ee142af Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 23 Mar 2023 11:34:03 -0700 Subject: [PATCH] Replace uses of ObjectReflectDiff with cmp.Diff ObjectReflectDiff is already a shim over cmp.Diff, so no actual output or behavior changes Kubernetes-commit: bc302fa4144d21a338683cd83701661f97be4aba --- discovery/discovery_client_test.go | 3 +-- metadata/metadata_test.go | 6 +++--- rest/request_test.go | 11 +++++------ tools/clientcmd/loader_test.go | 4 ++-- tools/events/event_broadcaster_test.go | 4 ++-- tools/leaderelection/leaderelection_test.go | 6 +++--- tools/watch/informerwatcher_test.go | 4 ++-- tools/watch/retrywatcher_test.go | 4 ++-- 8 files changed, 20 insertions(+), 22 deletions(-) diff --git a/discovery/discovery_client_test.go b/discovery/discovery_client_test.go index dc9a4ffe..7ed6948a 100644 --- a/discovery/discovery_client_test.go +++ b/discovery/discovery_client_test.go @@ -36,7 +36,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/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/version" "k8s.io/client-go/openapi" @@ -437,7 +436,7 @@ func TestGetServerResourcesForGroupVersion(t *testing.T) { "extensions/v1beta10", } if !reflect.DeepEqual(expectedGroupVersions, serverGroupVersions) { - t.Errorf("unexpected group versions: %v", diff.ObjectReflectDiff(expectedGroupVersions, serverGroupVersions)) + t.Errorf("unexpected group versions: %v", cmp.Diff(expectedGroupVersions, serverGroupVersions)) } } diff --git a/metadata/metadata_test.go b/metadata/metadata_test.go index 5e34f008..ff52b5a1 100644 --- a/metadata/metadata_test.go +++ b/metadata/metadata_test.go @@ -26,11 +26,11 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" corev1 "k8s.io/api/core/v1" 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/client-go/rest" ) @@ -89,7 +89,7 @@ func TestClient(t *testing.T) { }, } if !reflect.DeepEqual(expect, obj) { - t.Fatal(diff.ObjectReflectDiff(expect, obj)) + t.Fatal(cmp.Diff(expect, obj)) } }, }, @@ -146,7 +146,7 @@ func TestClient(t *testing.T) { }, } if !reflect.DeepEqual(expect, objs.Items) { - t.Fatal(diff.ObjectReflectDiff(expect, objs.Items)) + t.Fatal(cmp.Diff(expect, objs.Items)) } }, }, diff --git a/rest/request_test.go b/rest/request_test.go index 9c36c0de..c833c555 100644 --- a/rest/request_test.go +++ b/rest/request_test.go @@ -45,7 +45,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/runtime/serializer/streaming" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/intstr" utilnet "k8s.io/apimachinery/pkg/util/net" "k8s.io/apimachinery/pkg/watch" @@ -925,22 +924,22 @@ func TestTransformUnstructuredError(t *testing.T) { expect = err } if !reflect.DeepEqual(expect, transformed) { - t.Errorf("unexpected Error(): %s", diff.ObjectReflectDiff(expect, transformed)) + t.Errorf("unexpected Error(): %s", cmp.Diff(expect, transformed)) } // verify result.Get properly transforms the error if _, err := result.Get(); !reflect.DeepEqual(expect, err) { - t.Errorf("unexpected error on Get(): %s", diff.ObjectReflectDiff(expect, err)) + t.Errorf("unexpected error on Get(): %s", cmp.Diff(expect, err)) } // verify result.Into properly handles the error if err := result.Into(&v1.Pod{}); !reflect.DeepEqual(expect, err) { - t.Errorf("unexpected error on Into(): %s", diff.ObjectReflectDiff(expect, err)) + t.Errorf("unexpected error on Into(): %s", cmp.Diff(expect, err)) } // verify result.Raw leaves the error in the untransformed state if _, err := result.Raw(); !reflect.DeepEqual(result.err, err) { - t.Errorf("unexpected error on Raw(): %s", diff.ObjectReflectDiff(expect, err)) + t.Errorf("unexpected error on Raw(): %s", cmp.Diff(expect, err)) } }) } @@ -1220,7 +1219,7 @@ func TestRequestWatch(t *testing.T) { t.Fatalf("Watch closed early, %d/%d read", i, len(testCase.Expect)) } if !reflect.DeepEqual(evt, out) { - t.Fatalf("Event %d does not match: %s", i, diff.ObjectReflectDiff(evt, out)) + t.Fatalf("Event %d does not match: %s", i, cmp.Diff(evt, out)) } } } diff --git a/tools/clientcmd/loader_test.go b/tools/clientcmd/loader_test.go index b641d1a2..ba42e56f 100644 --- a/tools/clientcmd/loader_test.go +++ b/tools/clientcmd/loader_test.go @@ -26,10 +26,10 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" "sigs.k8s.io/yaml" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdlatest "k8s.io/client-go/tools/clientcmd/api/latest" ) @@ -248,7 +248,7 @@ preferences: {} users: null `) if !bytes.Equal(expected, data) { - t.Error(diff.ObjectReflectDiff(string(expected), string(data))) + t.Error(cmp.Diff(string(expected), string(data))) } } diff --git a/tools/events/event_broadcaster_test.go b/tools/events/event_broadcaster_test.go index 23685b79..ac7f7abe 100644 --- a/tools/events/event_broadcaster_test.go +++ b/tools/events/event_broadcaster_test.go @@ -21,9 +21,9 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" eventsv1 "k8s.io/api/events/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/kubernetes/fake" ) @@ -96,7 +96,7 @@ func TestRecordEventToSink(t *testing.T) { recordedEvent := recordedEvents.Items[0] if !reflect.DeepEqual(recordedEvent, tc.expectedRecordedEvent) { - t.Errorf("expected to have recorded Event: %#+v, got: %#+v\n diff: %s", tc.expectedRecordedEvent, recordedEvent, diff.ObjectReflectDiff(tc.expectedRecordedEvent, recordedEvent)) + t.Errorf("expected to have recorded Event: %#+v, got: %#+v\n diff: %s", tc.expectedRecordedEvent, recordedEvent, cmp.Diff(tc.expectedRecordedEvent, recordedEvent)) } }) } diff --git a/tools/leaderelection/leaderelection_test.go b/tools/leaderelection/leaderelection_test.go index ed4e89ae..b3e8bea7 100644 --- a/tools/leaderelection/leaderelection_test.go +++ b/tools/leaderelection/leaderelection_test.go @@ -24,13 +24,13 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" coordinationv1 "k8s.io/api/coordination/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes/fake" fakeclient "k8s.io/client-go/testing" @@ -371,13 +371,13 @@ func TestLeaseSpecToLeaderElectionRecordRoundTrip(t *testing.T) { newSpec := rl.LeaderElectionRecordToLeaseSpec(oldRecord) if !equality.Semantic.DeepEqual(oldSpec, newSpec) { - t.Errorf("diff: %v", diff.ObjectReflectDiff(oldSpec, newSpec)) + t.Errorf("diff: %v", cmp.Diff(oldSpec, newSpec)) } newRecord := rl.LeaseSpecToLeaderElectionRecord(&newSpec) if !equality.Semantic.DeepEqual(oldRecord, newRecord) { - t.Errorf("diff: %v", diff.ObjectReflectDiff(oldRecord, newRecord)) + t.Errorf("diff: %v", cmp.Diff(oldRecord, newRecord)) } } diff --git a/tools/watch/informerwatcher_test.go b/tools/watch/informerwatcher_test.go index ce029b46..138502c8 100644 --- a/tools/watch/informerwatcher_test.go +++ b/tools/watch/informerwatcher_test.go @@ -25,13 +25,13 @@ import ( "time" "github.com/davecgh/go-spew/spew" + "github.com/google/go-cmp/cmp" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" 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/apimachinery/pkg/watch" fakeclientset "k8s.io/client-go/kubernetes/fake" testcore "k8s.io/client-go/testing" @@ -260,7 +260,7 @@ func TestNewInformerWatcher(t *testing.T) { sort.Sort(byEventTypeAndName(result)) if !reflect.DeepEqual(expected, result) { - t.Error(spew.Errorf("\nexpected: %#v,\ngot: %#v,\ndiff: %s", expected, result, diff.ObjectReflectDiff(expected, result))) + t.Error(spew.Errorf("\nexpected: %#v,\ngot: %#v,\ndiff: %s", expected, result, cmp.Diff(expected, result))) return } diff --git a/tools/watch/retrywatcher_test.go b/tools/watch/retrywatcher_test.go index 8adaa4b8..3871d98b 100644 --- a/tools/watch/retrywatcher_test.go +++ b/tools/watch/retrywatcher_test.go @@ -27,12 +27,12 @@ import ( "time" "github.com/davecgh/go-spew/spew" + "github.com/google/go-cmp/cmp" apierrors "k8s.io/apimachinery/pkg/api/errors" 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/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/tools/cache" @@ -564,7 +564,7 @@ func TestRetryWatcher(t *testing.T) { } if !reflect.DeepEqual(tc.expected, got) { - t.Fatal(spew.Errorf("expected %#+v, got %#+v;\ndiff: %s", tc.expected, got, diff.ObjectReflectDiff(tc.expected, got))) + t.Fatal(spew.Errorf("expected %#+v, got %#+v;\ndiff: %s", tc.expected, got, cmp.Diff(tc.expected, got))) } }) }