Replace uses of ObjectGoPrintDiff with cmp.Diff

ObjectGoPrintDiff is already a shim over cmp.Diff, so no actual output
or behavior changes
This commit is contained in:
Tim Hockin 2023-03-23 11:31:25 -07:00
parent 29c0b73d64
commit 9627c50ef3
No known key found for this signature in database
11 changed files with 28 additions and 28 deletions

View File

@ -21,10 +21,10 @@ import (
"reflect" "reflect"
"testing" "testing"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
corev1listers "k8s.io/client-go/listers/core/v1" corev1listers "k8s.io/client-go/listers/core/v1"
@ -162,7 +162,7 @@ func TestConfigMapCreation(t *testing.T) {
actions := client.Actions() actions := client.Actions()
if reflect.DeepEqual(actions, tc.ExpectActions) { if reflect.DeepEqual(actions, tc.ExpectActions) {
t.Errorf("Unexpected actions:\n%s", diff.ObjectGoPrintDiff(actions, tc.ExpectActions)) t.Errorf("Unexpected actions:\n%s", cmp.Diff(actions, tc.ExpectActions))
} }
}) })
} }

View File

@ -22,11 +22,11 @@ import (
"testing" "testing"
"time" "time"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz" fuzz "github.com/google/gofuzz"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
) )
@ -96,7 +96,7 @@ func TestStructuralKubeOpenAPIRoundtrip(t *testing.T) {
} }
if !reflect.DeepEqual(orig, s) { if !reflect.DeepEqual(orig, s) {
t.Fatalf("original and result differ: %v", diff.ObjectGoPrintDiff(orig, s)) t.Fatalf("original and result differ: %v", cmp.Diff(orig, s))
} }
} }
} }

View File

@ -24,15 +24,15 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
apiequality "k8s.io/apimachinery/pkg/api/equality" apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/testapigroup/v1" v1 "k8s.io/apimachinery/pkg/apis/testapigroup/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer/protobuf" "k8s.io/apimachinery/pkg/runtime/serializer/protobuf"
"k8s.io/apimachinery/pkg/util/diff"
) )
type testObject struct { type testObject struct {
@ -355,7 +355,7 @@ func TestDecodeObjects(t *testing.T) {
} }
if !apiequality.Semantic.DeepEqual(obj, test.obj) { if !apiequality.Semantic.DeepEqual(obj, test.obj) {
t.Errorf("%d: unexpected object:\n%s", i, diff.ObjectGoPrintDiff(test.obj, obj)) t.Errorf("%d: unexpected object:\n%s", i, cmp.Diff(test.obj, obj))
continue continue
} }
} }

View File

@ -23,7 +23,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"k8s.io/apimachinery/pkg/util/diff" "github.com/google/go-cmp/cmp"
"k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/authentication/user"
) )
@ -219,7 +219,7 @@ func TestAuthenticate(t *testing.T) {
t.Errorf("Unexpected authentication. got=%v, want=%v", got, want) t.Errorf("Unexpected authentication. got=%v, want=%v", got, want)
} }
if got, want := resp, treq.wantResp; !reflect.DeepEqual(got, want) { if got, want := resp, treq.wantResp; !reflect.DeepEqual(got, want) {
t.Errorf("Unexpected response. diff:\n%v", diff.ObjectGoPrintDiff(got, want)) t.Errorf("Unexpected response. diff:\n%v", cmp.Diff(got, want))
} }
}) })
} }

View File

@ -28,6 +28,7 @@ import (
"time" "time"
jsonpatch "github.com/evanphx/json-patch" jsonpatch "github.com/evanphx/json-patch"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz" fuzz "github.com/google/gofuzz"
apiequality "k8s.io/apimachinery/pkg/api/equality" apiequality "k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
@ -583,7 +584,7 @@ func (tc *patchTestCase) Run(t *testing.T) {
reallyExpectedPod := expectedObj.(*example.Pod) reallyExpectedPod := expectedObj.(*example.Pod)
if !reflect.DeepEqual(*reallyExpectedPod, *resultPod) { if !reflect.DeepEqual(*reallyExpectedPod, *resultPod) {
t.Errorf("%s mismatch: %v\n", tc.name, diff.ObjectGoPrintDiff(reallyExpectedPod, resultPod)) t.Errorf("%s mismatch: %v\n", tc.name, cmp.Diff(reallyExpectedPod, resultPod))
continue continue
} }
} }

View File

@ -34,9 +34,9 @@ import (
"text/template" "text/template"
"time" "time"
"github.com/google/go-cmp/cmp"
authorizationv1 "k8s.io/api/authorization/v1" authorizationv1 "k8s.io/api/authorization/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/authorization/authorizer"
@ -556,7 +556,7 @@ func TestV1Webhook(t *testing.T) {
continue continue
} }
if !reflect.DeepEqual(gotAttr, tt.want) { if !reflect.DeepEqual(gotAttr, tt.want) {
t.Errorf("case %d: got != want:\n%s", i, diff.ObjectGoPrintDiff(gotAttr, tt.want)) t.Errorf("case %d: got != want:\n%s", i, cmp.Diff(gotAttr, tt.want))
} }
} }
} }

View File

@ -34,9 +34,9 @@ import (
"text/template" "text/template"
"time" "time"
"github.com/google/go-cmp/cmp"
authorizationv1beta1 "k8s.io/api/authorization/v1beta1" authorizationv1beta1 "k8s.io/api/authorization/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/authorization/authorizer"
webhookutil "k8s.io/apiserver/pkg/util/webhook" webhookutil "k8s.io/apiserver/pkg/util/webhook"
@ -548,7 +548,7 @@ func TestV1beta1Webhook(t *testing.T) {
continue continue
} }
if !reflect.DeepEqual(gotAttr, tt.want) { if !reflect.DeepEqual(gotAttr, tt.want) {
t.Errorf("case %d: got != want:\n%s", i, diff.ObjectGoPrintDiff(gotAttr, tt.want)) t.Errorf("case %d: got != want:\n%s", i, cmp.Diff(gotAttr, tt.want))
} }
} }
} }

View File

@ -28,7 +28,6 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/diff"
) )
const ( const (
@ -80,7 +79,7 @@ func TestGet(t *testing.T) {
}, },
} }
if !equality.Semantic.DeepEqual(get, expected) { if !equality.Semantic.DeepEqual(get, expected) {
t.Fatal(diff.ObjectGoPrintDiff(expected, get)) t.Fatal(cmp.Diff(expected, get))
} }
} }
@ -99,7 +98,7 @@ func TestListDecoding(t *testing.T) {
Items: []unstructured.Unstructured{}, Items: []unstructured.Unstructured{},
} }
if !equality.Semantic.DeepEqual(list, expectedList) { if !equality.Semantic.DeepEqual(list, expectedList) {
t.Fatal(diff.ObjectGoPrintDiff(expectedList, list)) t.Fatal(cmp.Diff(expectedList, list))
} }
} }
@ -117,7 +116,7 @@ func TestGetDecoding(t *testing.T) {
}, },
} }
if !equality.Semantic.DeepEqual(get, expectedObj) { if !equality.Semantic.DeepEqual(get, expectedObj) {
t.Fatal(diff.ObjectGoPrintDiff(expectedObj, get)) t.Fatal(cmp.Diff(expectedObj, get))
} }
} }
@ -145,7 +144,7 @@ func TestList(t *testing.T) {
*newUnstructured("group/version", "TheKind", "ns-foo", "name-foo"), *newUnstructured("group/version", "TheKind", "ns-foo", "name-foo"),
} }
if !equality.Semantic.DeepEqual(listFirst.Items, expected) { if !equality.Semantic.DeepEqual(listFirst.Items, expected) {
t.Fatal(diff.ObjectGoPrintDiff(expected, listFirst.Items)) t.Fatal(cmp.Diff(expected, listFirst.Items))
} }
} }
@ -189,7 +188,7 @@ func Test_ListKind(t *testing.T) {
}, },
} }
if !equality.Semantic.DeepEqual(listFirst, expectedList) { if !equality.Semantic.DeepEqual(listFirst, expectedList) {
t.Fatal(diff.ObjectGoPrintDiff(expectedList, listFirst)) t.Fatal(cmp.Diff(expectedList, listFirst))
} }
} }
@ -242,7 +241,7 @@ func (tc *patchTestCase) verifyResult(result *unstructured.Unstructured) error {
return nil return nil
} }
if !equality.Semantic.DeepEqual(result, tc.expectedPatchedObject) { if !equality.Semantic.DeepEqual(result, tc.expectedPatchedObject) {
return fmt.Errorf("unexpected diff in received object: %s", diff.ObjectGoPrintDiff(tc.expectedPatchedObject, result)) return fmt.Errorf("unexpected diff in received object: %s", cmp.Diff(tc.expectedPatchedObject, result))
} }
return nil return nil
} }

View File

@ -21,12 +21,12 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/diff"
) )
const ( const (
@ -79,7 +79,7 @@ func TestList(t *testing.T) {
*newPartialObjectMetadata("group/version", "TheKind", "ns-foo", "name-foo"), *newPartialObjectMetadata("group/version", "TheKind", "ns-foo", "name-foo"),
} }
if !equality.Semantic.DeepEqual(listFirst.Items, expected) { if !equality.Semantic.DeepEqual(listFirst.Items, expected) {
t.Fatal(diff.ObjectGoPrintDiff(expected, listFirst.Items)) t.Fatal(cmp.Diff(expected, listFirst.Items))
} }
} }
@ -134,7 +134,7 @@ func (tc *patchTestCase) verifyResult(result *metav1.PartialObjectMetadata) erro
return nil return nil
} }
if !equality.Semantic.DeepEqual(result, tc.expectedPatchedObject) { if !equality.Semantic.DeepEqual(result, tc.expectedPatchedObject) {
return fmt.Errorf("unexpected diff in received object: %s", diff.ObjectGoPrintDiff(tc.expectedPatchedObject, result)) return fmt.Errorf("unexpected diff in received object: %s", cmp.Diff(tc.expectedPatchedObject, result))
} }
return nil return nil
} }

View File

@ -23,9 +23,9 @@ import (
"testing" "testing"
"time" "time"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/diff"
testclocks "k8s.io/utils/clock/testing" testclocks "k8s.io/utils/clock/testing"
) )
@ -121,7 +121,7 @@ func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v
} }
recvEvent.Name = expectedEvent.Name recvEvent.Name = expectedEvent.Name
if e, a := expectedEvent, &recvEvent; !reflect.DeepEqual(e, a) { if e, a := expectedEvent, &recvEvent; !reflect.DeepEqual(e, a) {
t.Errorf("%v - diff: %s", messagePrefix, diff.ObjectGoPrintDiff(e, a)) t.Errorf("%v - diff: %s", messagePrefix, cmp.Diff(e, a))
} }
recvEvent.FirstTimestamp = actualFirstTimestamp recvEvent.FirstTimestamp = actualFirstTimestamp
recvEvent.LastTimestamp = actualLastTimestamp recvEvent.LastTimestamp = actualLastTimestamp

View File

@ -25,6 +25,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/google/go-cmp/cmp"
clientv3 "go.etcd.io/etcd/client/v3" clientv3 "go.etcd.io/etcd/client/v3"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
@ -33,7 +34,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apiserver/pkg/util/feature" "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic"
@ -203,7 +203,7 @@ func TestEtcdStoragePath(t *testing.T) {
} }
if !apiequality.Semantic.DeepDerivative(input, output) { if !apiequality.Semantic.DeepDerivative(input, output) {
t.Errorf("Test stub for %s does not match: %s", kind, diff.ObjectGoPrintDiff(input, output)) t.Errorf("Test stub for %s does not match: %s", kind, cmp.Diff(input, output))
} }
addGVKToEtcdBucket(cohabitatingResources, actualGVK, getEtcdBucket(testData.ExpectedEtcdPath)) addGVKToEtcdBucket(cohabitatingResources, actualGVK, getEtcdBucket(testData.ExpectedEtcdPath))