Merge pull request #116896 from thockin/apimachinery_util_diff_cleanup

apimachinery util/diff cleanups
This commit is contained in:
Kubernetes Prow Robot
2023-04-13 02:26:37 -07:00
committed by GitHub
134 changed files with 458 additions and 524 deletions

View File

@@ -22,11 +22,11 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/json"
)
@@ -96,7 +96,7 @@ func TestStructuralKubeOpenAPIRoundtrip(t *testing.T) {
}
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

@@ -21,6 +21,7 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
"k8s.io/apimachinery/pkg/api/equality"
@@ -30,7 +31,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/apimachinery/pkg/util/diff"
utiljson "k8s.io/apimachinery/pkg/util/json"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
)
@@ -56,7 +56,7 @@ func TestRoundtripObjectMeta(t *testing.T) {
}
if !equality.Semantic.DeepEqual(original, o) {
t.Errorf("diff: %v\nCodec: %#v", diff.ObjectReflectDiff(original, o), codec)
t.Errorf("diff: %v\nCodec: %#v", cmp.Diff(original, o), codec)
}
}
}
@@ -153,7 +153,7 @@ func TestMalformedObjectMetaFields(t *testing.T) {
}
if !equality.Semantic.DeepEqual(expectedObjectMeta, actualObjectMeta) {
t.Errorf("%v=%#v, diff: %v\n", pth, v, diff.ObjectReflectDiff(expectedObjectMeta, actualObjectMeta))
t.Errorf("%v=%#v, diff: %v\n", pth, v, cmp.Diff(expectedObjectMeta, actualObjectMeta))
t.Errorf("expectedObjectMeta %#v", expectedObjectMeta)
}
}

View File

@@ -21,13 +21,13 @@ import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
apiextensionsinternal "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
structuralschema "k8s.io/apiextensions-apiserver/pkg/apiserver/schema"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apiserver/pkg/endpoints"
@@ -438,7 +438,7 @@ func TestNewBuilder(t *testing.T) {
gotListSchema := got.listSchema.Properties["items"].Items.Schema
if !reflect.DeepEqual(&wantedItemsSchema, gotListSchema) {
t.Errorf("unexpected list schema: %s (want/got)", schemaDiff(&wantedItemsSchema, gotListSchema))
t.Errorf("unexpected list schema:\n%s", schemaDiff(&wantedItemsSchema, gotListSchema))
}
})
}
@@ -560,15 +560,8 @@ func properties(p map[string]spec.Schema) sets.String {
}
func schemaDiff(a, b *spec.Schema) string {
as, err := json.Marshal(a)
if err != nil {
panic(err)
}
bs, err := json.Marshal(b)
if err != nil {
panic(err)
}
return diff.StringDiff(string(as), string(bs))
// This option construct allows diffing all fields, even unexported ones.
return cmp.Diff(a, b, cmp.Exporter(func(reflect.Type) bool { return true }))
}
func TestBuildOpenAPIV2(t *testing.T) {

View File

@@ -23,11 +23,11 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/client-go/util/jsonpath"
)
@@ -434,7 +434,7 @@ func Test_convertor_ConvertToTable(t *testing.T) {
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("convertor.ConvertToTable() = %s", diff.ObjectReflectDiff(tt.want, got))
t.Errorf("convertor.ConvertToTable() = %s", cmp.Diff(tt.want, got))
}
})
}

View File

@@ -26,6 +26,7 @@ import (
//nolint:staticcheck //iccheck // SA1019 Keep using deprecated module; it still seems to be maintained and the api of the recommended replacement differs
"github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz"
flag "github.com/spf13/pflag"
@@ -39,7 +40,6 @@ import (
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/apimachinery/pkg/runtime/serializer/protobuf"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/dump"
"k8s.io/apimachinery/pkg/util/sets"
)
@@ -305,7 +305,7 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, 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("%v: DeepCopy altered the object, diff: %v", name, cmp.Diff(original, object))
t.Errorf("%s", dump.Pretty(original))
t.Errorf("%s", dump.Pretty(object))
return
@@ -326,7 +326,7 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object
// copy or conversion should alter the object
// TODO eliminate this global
if !apiequality.Semantic.DeepEqual(original, object) {
t.Errorf("%v: encode altered the object, diff: %v", name, diff.ObjectReflectDiff(original, object))
t.Errorf("%v: encode altered the object, diff: %v", name, cmp.Diff(original, object))
return
}
@@ -357,7 +357,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(original, obj2), codec, dump.Pretty(original), dataAsString(data), dump.Pretty(obj2))
t.Errorf("%v: diff: %v\nCodec: %#v\nSource:\n\n%#v\n\nEncoded:\n\n%s\n\nFinal:\n\n%#v", name, cmp.Diff(original, obj2), codec, dump.Pretty(original), dataAsString(data), dump.Pretty(obj2))
return
}
@@ -395,7 +395,7 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object
// ensure that the new runtime object is equal to the original after being
// decoded into
if !apiequality.Semantic.DeepEqual(object, obj3) {
t.Errorf("%v: diff: %v\nCodec: %#v", name, diff.ObjectReflectDiff(object, obj3), codec)
t.Errorf("%v: diff: %v\nCodec: %#v", name, cmp.Diff(object, obj3), codec)
return
}
@@ -404,7 +404,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, obj3))
t.Errorf("%v: fuzzing a copy altered the original, diff: %v", name, cmp.Diff(original, obj3))
return
}
}

View File

@@ -23,8 +23,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/util/diff"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz"
)
@@ -36,7 +36,7 @@ func TestAsPartialObjectMetadata(t *testing.T) {
f.Fuzz(m)
partial := AsPartialObjectMetadata(m)
if !reflect.DeepEqual(&partial.ObjectMeta, m) {
t.Fatalf("incomplete partial object metadata: %s", diff.ObjectReflectDiff(&partial.ObjectMeta, m))
t.Fatalf("incomplete partial object metadata: %s", cmp.Diff(&partial.ObjectMeta, m))
}
}
@@ -45,7 +45,7 @@ func TestAsPartialObjectMetadata(t *testing.T) {
f.Fuzz(&m.ObjectMeta)
partial := AsPartialObjectMetadata(m)
if !reflect.DeepEqual(&partial.ObjectMeta, &m.ObjectMeta) {
t.Fatalf("incomplete partial object metadata: %s", diff.ObjectReflectDiff(&partial.ObjectMeta, &m.ObjectMeta))
t.Fatalf("incomplete partial object metadata: %s", cmp.Diff(&partial.ObjectMeta, &m.ObjectMeta))
}
}
}

View File

@@ -21,9 +21,9 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/diff"
)
func TestListOptions(t *testing.T) {
@@ -45,7 +45,7 @@ func TestListOptions(t *testing.T) {
t.Fatal(err)
}
if !reflect.DeepEqual(in, actual) {
t.Errorf("unexpected: %s", diff.ObjectReflectDiff(in, actual))
t.Errorf("unexpected: %s", cmp.Diff(in, actual))
}
// verify failing conversion
@@ -85,6 +85,6 @@ func TestListOptions(t *testing.T) {
t.Fatal(err)
}
if !reflect.DeepEqual(in, actual) {
t.Errorf("unexpected: %s", diff.ObjectReflectDiff(in, actual))
t.Errorf("unexpected: %s", cmp.Diff(in, actual))
}
}

View File

@@ -22,10 +22,10 @@ import (
"strings"
"testing"
"github.com/google/gofuzz"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/diff"
)
func TestLabelSelectorAsSelector(t *testing.T) {
@@ -211,7 +211,7 @@ func TestResetObjectMetaForStatus(t *testing.T) {
existingMeta.SetManagedFields(nil)
if !reflect.DeepEqual(meta, existingMeta) {
t.Error(diff.ObjectDiff(meta, existingMeta))
t.Error(cmp.Diff(meta, existingMeta))
}
}

View File

@@ -21,6 +21,7 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
"k8s.io/apimachinery/pkg/api/equality"
@@ -29,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/diff"
)
func TestNilUnstructuredContent(t *testing.T) {
@@ -65,7 +65,7 @@ func TestUnstructuredMetadataRoundTrip(t *testing.T) {
setObjectMetaUsingAccessors(u, uCopy)
if !equality.Semantic.DeepEqual(u, uCopy) {
t.Errorf("diff: %v", diff.ObjectReflectDiff(u, uCopy))
t.Errorf("diff: %v", cmp.Diff(u, uCopy))
}
}
}

View File

@@ -33,9 +33,9 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/json"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -194,7 +194,7 @@ func doRoundTrip(t *testing.T, item interface{}) {
return
}
if !reflect.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
}
@@ -213,7 +213,7 @@ func doRoundTrip(t *testing.T, item interface{}) {
}
if !reflect.DeepEqual(item, newObj) {
t.Errorf("Object changed, diff: %v", diff.ObjectReflectDiff(item, newObj))
t.Errorf("Object changed, diff: %v", cmp.Diff(item, newObj))
}
}
@@ -687,7 +687,7 @@ func doUnrecognized(t *testing.T, jsonData string, item interface{}, expectedErr
}
if expectedErr == nil && !reflect.DeepEqual(unmarshalledObj, newObj) {
t.Errorf("Object changed, diff: %v", diff.ObjectReflectDiff(unmarshalledObj, newObj))
t.Errorf("Object changed, diff: %v", cmp.Diff(unmarshalledObj, newObj))
}
}
@@ -916,7 +916,7 @@ func TestFloatIntConversion(t *testing.T) {
}
if !reflect.DeepEqual(obj, unmarshalled) {
t.Errorf("Incorrect conversion, diff: %v", diff.ObjectReflectDiff(obj, unmarshalled))
t.Errorf("Incorrect conversion, diff: %v", cmp.Diff(obj, unmarshalled))
}
}
@@ -938,7 +938,7 @@ func TestIntFloatConversion(t *testing.T) {
}
if !reflect.DeepEqual(obj, unmarshalled) {
t.Errorf("Incorrect conversion, diff: %v", diff.ObjectReflectDiff(obj, unmarshalled))
t.Errorf("Incorrect conversion, diff: %v", cmp.Diff(obj, unmarshalled))
}
}

View File

@@ -21,8 +21,8 @@ import (
"reflect"
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"
)
func TestPreferredVersionsAllGroups(t *testing.T) {
@@ -124,7 +124,7 @@ func TestPreferredVersionsAllGroups(t *testing.T) {
for group, expected := range test.expectedPrioritized {
actual := scheme.PrioritizedVersionsForGroup(group)
if !reflect.DeepEqual(expected, actual) {
t.Error(diff.ObjectDiff(expected, actual))
t.Error(cmp.Diff(expected, actual))
}
}
@@ -134,7 +134,7 @@ func TestPreferredVersionsAllGroups(t *testing.T) {
actualPrioritizedAll[actual.Group] = append(actualPrioritizedAll[actual.Group], actual)
}
if !reflect.DeepEqual(test.expectedPrioritized, actualPrioritizedAll) {
t.Error(diff.ObjectDiff(test.expectedPrioritized, actualPrioritizedAll))
t.Error(cmp.Diff(test.expectedPrioritized, actualPrioritizedAll))
}
preferredAll := scheme.PreferredVersionAllGroups()
@@ -143,7 +143,7 @@ func TestPreferredVersionsAllGroups(t *testing.T) {
actualPreferredAll[actual] = true
}
if !reflect.DeepEqual(test.expectedPreferred, actualPreferredAll) {
t.Error(diff.ObjectDiff(test.expectedPreferred, actualPreferredAll))
t.Error(cmp.Diff(test.expectedPreferred, actualPreferredAll))
}
})
}

View File

@@ -20,8 +20,8 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"
)
func TestResourceMapper(t *testing.T) {
@@ -122,14 +122,14 @@ func TestResourceMapper(t *testing.T) {
// Verify equivalents to primary resource
if resources := mapper.EquivalentResourcesFor(gvr("apps", "v1", "deployments"), ""); !reflect.DeepEqual(resources, tc.ResourcesForV1Deployment) {
t.Errorf("diff:\n%s", diff.ObjectReflectDiff(tc.ResourcesForV1Deployment, resources))
t.Errorf("diff:\n%s", cmp.Diff(tc.ResourcesForV1Deployment, resources))
}
// Verify equivalents to subresources
if resources := mapper.EquivalentResourcesFor(gvr("apps", "v1", "deployments"), "scale"); !reflect.DeepEqual(resources, tc.ResourcesForV1DeploymentScale) {
t.Errorf("diff:\n%s", diff.ObjectReflectDiff(tc.ResourcesForV1DeploymentScale, resources))
t.Errorf("diff:\n%s", cmp.Diff(tc.ResourcesForV1DeploymentScale, resources))
}
if resources := mapper.EquivalentResourcesFor(gvr("apps", "v1", "deployments"), "status"); !reflect.DeepEqual(resources, tc.ResourcesForV1DeploymentStatus) {
t.Errorf("diff:\n%s", diff.ObjectReflectDiff(tc.ResourcesForV1DeploymentStatus, resources))
t.Errorf("diff:\n%s", cmp.Diff(tc.ResourcesForV1DeploymentStatus, resources))
}
})
}

View File

@@ -22,6 +22,7 @@ import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -856,17 +857,17 @@ func TestConvertToVersion(t *testing.T) {
if test.same {
if !reflect.DeepEqual(original, test.in) {
t.Fatalf("unexpected mutation of input: %s", diff.ObjectReflectDiff(original, test.in))
t.Fatalf("unexpected mutation of input: %s", cmp.Diff(original, test.in))
}
if !reflect.DeepEqual(out, test.out) {
t.Fatalf("unexpected out: %s", diff.ObjectReflectDiff(out, test.out))
t.Fatalf("unexpected out: %s", cmp.Diff(out, test.out))
}
unsafe, err := test.scheme.UnsafeConvertToVersion(test.in, test.gv)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !reflect.DeepEqual(unsafe, test.out) {
t.Fatalf("unexpected unsafe: %s", diff.ObjectReflectDiff(unsafe, test.out))
t.Fatalf("unexpected unsafe: %s", cmp.Diff(unsafe, test.out))
}
if unsafe != test.in {
t.Fatalf("UnsafeConvertToVersion should return same object: %#v", unsafe)
@@ -874,7 +875,7 @@ func TestConvertToVersion(t *testing.T) {
return
}
if !reflect.DeepEqual(out, test.out) {
t.Fatalf("unexpected out: %s", diff.ObjectReflectDiff(out, test.out))
t.Fatalf("unexpected out: %s", cmp.Diff(out, test.out))
}
})
}
@@ -917,7 +918,7 @@ func TestConvert(t *testing.T) {
}
if !reflect.DeepEqual(test.into, test.out) {
t.Fatalf("unexpected out: %s", diff.ObjectReflectDiff(test.into, test.out))
t.Fatalf("unexpected out: %s", cmp.Diff(test.into, test.out))
}
})
}

View File

@@ -33,6 +33,7 @@ import (
"k8s.io/apimachinery/pkg/util/diff"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz"
flag "github.com/spf13/pflag"
"sigs.k8s.io/yaml"
@@ -128,7 +129,7 @@ func runTest(t *testing.T, source interface{}) {
return
}
if !semantic.DeepEqual(source, obj3) {
t.Errorf("3: %v: diff: %v", name, diff.ObjectDiff(source, obj3))
t.Errorf("3: %v: diff: %v", name, cmp.Diff(source, obj3))
return
}
}

View File

@@ -19,11 +19,11 @@ package serializer
import (
"testing"
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/api/equality"
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"
)
type FakeV1Obj struct {
@@ -83,9 +83,9 @@ func TestSparse(t *testing.T) {
uncastDstObj2.(*FakeV2DifferentObj).TypeMeta = metav1.TypeMeta{}
if !equality.Semantic.DeepEqual(srcObj1, uncastDstObj1) {
t.Fatal(diff.ObjectDiff(srcObj1, uncastDstObj1))
t.Fatal(cmp.Diff(srcObj1, uncastDstObj1))
}
if !equality.Semantic.DeepEqual(srcObj2, uncastDstObj2) {
t.Fatal(diff.ObjectDiff(srcObj2, uncastDstObj2))
t.Fatal(cmp.Diff(srcObj2, uncastDstObj2))
}
}

View File

@@ -20,6 +20,7 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz"
"k8s.io/apimachinery/pkg/api/meta"
@@ -27,11 +28,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/apis/testapigroup"
"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/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/diff"
)
func TestIsList(t *testing.T) {
@@ -283,7 +283,7 @@ func TestSetListToRuntimeObjectArray(t *testing.T) {
}
for i := range list {
if e, a := list[i], pl.Items[i]; e != a {
t.Fatalf("%d: unmatched: %s", i, diff.ObjectDiff(e, a))
t.Fatalf("%d: unmatched: %s", i, cmp.Diff(e, a))
}
}
}
@@ -304,7 +304,7 @@ func TestSetListToMatchingType(t *testing.T) {
}
for i := range list {
if e, a := list[i], &pl.Items[i]; !reflect.DeepEqual(e, a) {
t.Fatalf("%d: unmatched: %s", i, diff.ObjectDiff(e, a))
t.Fatalf("%d: unmatched: %s", i, cmp.Diff(e, a))
}
}
}

View File

@@ -24,15 +24,15 @@ import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
apiequality "k8s.io/apimachinery/pkg/api/equality"
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/schema"
"k8s.io/apimachinery/pkg/runtime/serializer/protobuf"
"k8s.io/apimachinery/pkg/util/diff"
)
type testObject struct {
@@ -355,7 +355,7 @@ func TestDecodeObjects(t *testing.T) {
}
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
}
}

View File

@@ -27,30 +27,16 @@ import (
"k8s.io/apimachinery/pkg/util/dump"
)
// StringDiff diffs a and b and returns a human readable diff.
func StringDiff(a, b string) string {
ba := []byte(a)
bb := []byte(b)
out := []byte{}
i := 0
for ; i < len(ba) && i < len(bb); i++ {
if ba[i] != bb[i] {
break
}
out = append(out, ba[i])
}
out = append(out, []byte("\n\nA: ")...)
out = append(out, ba[i:]...)
out = append(out, []byte("\n\nB: ")...)
out = append(out, bb[i:]...)
out = append(out, []byte("\n\n")...)
return string(out)
}
func legacyDiff(a, b interface{}) string {
return cmp.Diff(a, b)
}
// StringDiff diffs a and b and returns a human readable diff.
// DEPRECATED: use github.com/google/go-cmp/cmp.Diff
func StringDiff(a, b string) string {
return legacyDiff(a, b)
}
// ObjectDiff prints the diff of two go objects and fails if the objects
// contain unhandled unexported fields.
// DEPRECATED: use github.com/google/go-cmp/cmp.Diff

View File

@@ -1,29 +0,0 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package diff
import (
"testing"
)
func TestStringDiff(t *testing.T) {
diff := StringDiff("aaabb", "aaacc")
expect := "aaa\n\nA: bb\n\nB: cc\n\n"
if diff != expect {
t.Errorf("diff returned %v", diff)
}
}

View File

@@ -29,7 +29,7 @@ import (
"regexp"
"testing"
"k8s.io/apimachinery/pkg/util/diff"
"github.com/google/go-cmp/cmp"
utilnet "k8s.io/apimachinery/pkg/util/net"
)
@@ -147,7 +147,7 @@ func TestDialURL(t *testing.T) {
// Make sure dialing doesn't mutate the transport's TLSConfig
if !reflect.DeepEqual(tc.TLSConfig, tlsConfigCopy) {
t.Errorf("%s: transport's copy of TLSConfig was mutated\n%s", k, diff.ObjectReflectDiff(tc.TLSConfig, tlsConfigCopy))
t.Errorf("%s: transport's copy of TLSConfig was mutated\n%s", k, cmp.Diff(tc.TLSConfig, tlsConfigCopy))
}
if err != nil {

View File

@@ -21,13 +21,13 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"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/apiserver/pkg/apis/example"
examplev1 "k8s.io/apiserver/pkg/apis/example/v1"
example2v1 "k8s.io/apiserver/pkg/apis/example2/v1"
@@ -341,22 +341,22 @@ func TestConvertVersionedAttributes(t *testing.T) {
t.Fatal(err)
}
if e, a := tc.ExpectedAttrs.Attributes.GetObject(), tc.Attrs.Attributes.GetObject(); !reflect.DeepEqual(e, a) {
t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a))
t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a))
}
if e, a := tc.ExpectedAttrs.Attributes.GetOldObject(), tc.Attrs.Attributes.GetOldObject(); !reflect.DeepEqual(e, a) {
t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a))
t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a))
}
if e, a := tc.ExpectedAttrs.VersionedKind, tc.Attrs.VersionedKind; !reflect.DeepEqual(e, a) {
t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a))
t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a))
}
if e, a := tc.ExpectedAttrs.VersionedObject, tc.Attrs.VersionedObject; !reflect.DeepEqual(e, a) {
t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a))
t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a))
}
if e, a := tc.ExpectedAttrs.VersionedOldObject, tc.Attrs.VersionedOldObject; !reflect.DeepEqual(e, a) {
t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a))
t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a))
}
if e, a := tc.ExpectedAttrs.Dirty, tc.Attrs.Dirty; !reflect.DeepEqual(e, a) {
t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a))
t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a))
}
})
}

View File

@@ -23,12 +23,12 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1"
"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/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/admission"
@@ -202,7 +202,7 @@ func TestAdmissionNamespaceTerminating(t *testing.T) {
Field: "metadata.namespace",
}
if cause, ok := errors.StatusCause(err, v1.NamespaceTerminatingCause); !ok || !reflect.DeepEqual(expectedCause, cause) {
t.Errorf("Expected status cause indicating the namespace is terminating: %t %s", ok, diff.ObjectReflectDiff(expectedCause, cause))
t.Errorf("Expected status cause indicating the namespace is terminating: %t %s", ok, cmp.Diff(expectedCause, cause))
}
// verify update operations in the namespace can proceed

View File

@@ -21,9 +21,9 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz"
"k8s.io/api/admissionregistration/v1"
"k8s.io/apimachinery/pkg/util/diff"
v1 "k8s.io/api/admissionregistration/v1"
)
func TestMutatingWebhookAccessor(t *testing.T) {
@@ -46,7 +46,7 @@ func TestMutatingWebhookAccessor(t *testing.T) {
t.Errorf("expected GetMutatingWebhook to return ok for mutating webhook accessor")
}
if !reflect.DeepEqual(orig, m) {
t.Errorf("expected GetMutatingWebhook to return original webhook, diff:\n%s", diff.ObjectReflectDiff(orig, m))
t.Errorf("expected GetMutatingWebhook to return original webhook, diff:\n%s", cmp.Diff(orig, m))
}
if _, ok := accessor.GetValidatingWebhook(); ok {
t.Errorf("expected GetValidatingWebhook to be nil for mutating webhook accessor")
@@ -65,7 +65,7 @@ func TestMutatingWebhookAccessor(t *testing.T) {
MatchConditions: accessor.GetMatchConditions(),
}
if !reflect.DeepEqual(orig, copy) {
t.Errorf("expected mutatingWebhook to round trip through WebhookAccessor, diff:\n%s", diff.ObjectReflectDiff(orig, copy))
t.Errorf("expected mutatingWebhook to round trip through WebhookAccessor, diff:\n%s", cmp.Diff(orig, copy))
}
})
}
@@ -87,7 +87,7 @@ func TestValidatingWebhookAccessor(t *testing.T) {
t.Errorf("expected GetValidatingWebhook to return ok for validating webhook accessor")
}
if !reflect.DeepEqual(orig, m) {
t.Errorf("expected GetValidatingWebhook to return original webhook, diff:\n%s", diff.ObjectReflectDiff(orig, m))
t.Errorf("expected GetValidatingWebhook to return original webhook, diff:\n%s", cmp.Diff(orig, m))
}
if _, ok := accessor.GetMutatingWebhook(); ok {
t.Errorf("expected GetMutatingWebhook to be nil for validating webhook accessor")
@@ -106,7 +106,7 @@ func TestValidatingWebhookAccessor(t *testing.T) {
MatchConditions: accessor.GetMatchConditions(),
}
if !reflect.DeepEqual(orig, copy) {
t.Errorf("expected validatingWebhook to round trip through WebhookAccessor, diff:\n%s", diff.ObjectReflectDiff(orig, copy))
t.Errorf("expected validatingWebhook to round trip through WebhookAccessor, diff:\n%s", cmp.Diff(orig, copy))
}
})
}

View File

@@ -21,9 +21,9 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apiserver/pkg/admission"
)
@@ -63,7 +63,7 @@ func (r *reinvoker) Admit(ctx context.Context, a admission.Attributes, o admissi
}
for i := 1; i < len(outputs); i++ {
if !apiequality.Semantic.DeepEqual(outputs[0], outputs[i]) {
r.t.Errorf("expected mutating admission plugin to be idempontent, but got different results on reinvocation, diff:\n%s", diff.ObjectReflectDiff(outputs[0], outputs[i]))
r.t.Errorf("expected mutating admission plugin to be idempontent, but got different results on reinvocation, diff:\n%s", cmp.Diff(outputs[0], outputs[i]))
}
}
return nil

View File

@@ -23,12 +23,12 @@ import (
"strings"
"testing"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apiserver/pkg/apis/audit"
// import to call webhook's init() function to register audit.Policy to schema
_ "k8s.io/apiserver/plugin/pkg/audit/webhook"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -113,7 +113,7 @@ func TestParser(t *testing.T) {
assert.Len(t, policy.Rules, 3) // Sanity check.
if !reflect.DeepEqual(policy, expectedPolicy) {
t.Errorf("Unexpected policy! Diff:\n%s", diff.ObjectDiff(policy, expectedPolicy))
t.Errorf("Unexpected policy! Diff:\n%s", cmp.Diff(policy, expectedPolicy))
}
}

View File

@@ -23,7 +23,7 @@ import (
"reflect"
"testing"
"k8s.io/apimachinery/pkg/util/diff"
"github.com/google/go-cmp/cmp"
"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)
}
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

@@ -38,6 +38,7 @@ import (
"time"
"github.com/emicklei/go-restful/v3"
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
apiequality "k8s.io/apimachinery/pkg/api/equality"
@@ -55,7 +56,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/runtime/serializer/streaming"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/net"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/sets"
@@ -1832,7 +1832,7 @@ func TestGetTable(t *testing.T) {
}
if !reflect.DeepEqual(test.expected, &itemOut) {
t.Log(body)
t.Errorf("%d: did not match: %s", i, diff.ObjectReflectDiff(test.expected, &itemOut))
t.Errorf("%d: did not match: %s", i, cmp.Diff(test.expected, &itemOut))
}
})
}
@@ -2061,13 +2061,7 @@ func TestWatchTable(t *testing.T) {
actual = append(actual, &event)
}
if !reflect.DeepEqual(test.expected, actual) {
for i := range test.expected {
if i >= len(actual) {
break
}
t.Logf("%s", diff.StringDiff(string(test.expected[i].Object.Raw), string(actual[i].Object.Raw)))
}
t.Fatalf("unexpected: %s", diff.ObjectReflectDiff(test.expected, actual))
t.Fatalf("unexpected: %s", cmp.Diff(test.expected, actual))
}
})
}
@@ -2245,7 +2239,7 @@ func TestGetPartialObjectMetadata(t *testing.T) {
t.Fatal(err)
}
if !reflect.DeepEqual(test.expected, itemOut) {
t.Errorf("%d: did not match: %s", i, diff.ObjectReflectDiff(test.expected, itemOut))
t.Errorf("%d: did not match: %s", i, cmp.Diff(test.expected, itemOut))
}
body = d
} else {
@@ -2829,7 +2823,7 @@ func TestDeleteWithOptions(t *testing.T) {
}
simpleStorage.deleteOptions.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{})
if !apiequality.Semantic.DeepEqual(simpleStorage.deleteOptions, item) {
t.Errorf("unexpected delete options: %s", diff.ObjectDiff(simpleStorage.deleteOptions, item))
t.Errorf("unexpected delete options: %s", cmp.Diff(simpleStorage.deleteOptions, item))
}
}
@@ -2869,7 +2863,7 @@ func TestDeleteWithOptionsQuery(t *testing.T) {
}
simpleStorage.deleteOptions.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{})
if !apiequality.Semantic.DeepEqual(simpleStorage.deleteOptions, item) {
t.Errorf("unexpected delete options: %s", diff.ObjectDiff(simpleStorage.deleteOptions, item))
t.Errorf("unexpected delete options: %s", cmp.Diff(simpleStorage.deleteOptions, item))
}
}
@@ -2912,7 +2906,7 @@ func TestDeleteWithOptionsQueryAndBody(t *testing.T) {
}
simpleStorage.deleteOptions.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{})
if !apiequality.Semantic.DeepEqual(simpleStorage.deleteOptions, item) {
t.Errorf("unexpected delete options: %s", diff.ObjectDiff(simpleStorage.deleteOptions, item))
t.Errorf("unexpected delete options: %s", cmp.Diff(simpleStorage.deleteOptions, item))
}
}

View File

@@ -35,11 +35,11 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apiserver/pkg/features"
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -114,7 +114,7 @@ func TestSerializeObjectParallel(t *testing.T) {
t.Fatalf("unexpected code: %v", result.StatusCode)
}
if !reflect.DeepEqual(result.Header, ctt.wantHeaders) {
t.Fatal(diff.ObjectReflectDiff(ctt.wantHeaders, result.Header))
t.Fatal(cmp.Diff(ctt.wantHeaders, result.Header))
}
})
}
@@ -364,7 +364,7 @@ func TestSerializeObject(t *testing.T) {
t.Fatalf("unexpected code: %v", result.StatusCode)
}
if !reflect.DeepEqual(result.Header, tt.wantHeaders) {
t.Fatal(diff.ObjectReflectDiff(tt.wantHeaders, result.Header))
t.Fatal(cmp.Diff(tt.wantHeaders, result.Header))
}
body, _ := ioutil.ReadAll(result.Body)
if !bytes.Equal(tt.wantBody, body) {

View File

@@ -28,6 +28,7 @@ import (
"time"
jsonpatch "github.com/evanphx/json-patch"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz"
apiequality "k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -38,7 +39,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/json"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/strategicpatch"
@@ -583,7 +583,7 @@ func (tc *patchTestCase) Run(t *testing.T) {
reallyExpectedPod := expectedObj.(*example.Pod)
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
}
}
@@ -1279,7 +1279,7 @@ func TestDedupOwnerReferences(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
deduped, _ := dedupOwnerReferences(tc.ownerReferences)
if !apiequality.Semantic.DeepEqual(deduped, tc.expected) {
t.Errorf("diff: %v", diff.ObjectReflectDiff(deduped, tc.expected))
t.Errorf("diff: %v", cmp.Diff(deduped, tc.expected))
}
})
}

View File

@@ -32,6 +32,7 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"golang.org/x/net/websocket"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
@@ -41,7 +42,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer/streaming"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
example "k8s.io/apiserver/pkg/apis/example"
@@ -397,7 +397,7 @@ func TestWatchRead(t *testing.T) {
t.Fatalf("%s: Decode error: %v", name, err)
}
if e, a := object, gotObj; !apiequality.Semantic.DeepEqual(e, a) {
t.Errorf("%s: different: %s", name, diff.ObjectDiff(e, a))
t.Errorf("%s: different: %s", name, cmp.Diff(e, a))
}
}
w.Stop()

View File

@@ -24,13 +24,13 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"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/apiserver/pkg/storage"
@@ -189,7 +189,7 @@ TestCase:
for j, event := range testCase.expected {
e := <-ch
if !reflect.DeepEqual(event, e) {
t.Errorf("%d: unexpected event %d: %s", i, j, diff.ObjectReflectDiff(event, e))
t.Errorf("%d: unexpected event %d: %s", i, j, cmp.Diff(event, e))
break TestCase
}
}

View File

@@ -19,8 +19,8 @@ package webhook
import (
"testing"
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/client-go/rest"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)
@@ -230,7 +230,7 @@ func TestAuthenticationDetection(t *testing.T) {
actual.Timeout = 0
if !equality.Semantic.DeepEqual(*actual, tc.expected) {
t.Errorf("%v", diff.ObjectReflectDiff(tc.expected, *actual))
t.Errorf("%v", cmp.Diff(tc.expected, *actual))
}
})
}

View File

@@ -23,11 +23,11 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz"
authenticationv1 "k8s.io/api/authentication/v1"
authenticationv1beta1 "k8s.io/api/authentication/v1beta1"
"k8s.io/apimachinery/pkg/util/diff"
)
func TestRoundTrip(t *testing.T) {
@@ -49,7 +49,7 @@ func TestRoundTrip(t *testing.T) {
Status: v1beta1StatusToV1Status(&converted.Status),
}
if !reflect.DeepEqual(original, roundtripped) {
t.Errorf("diff %s", diff.ObjectReflectDiff(original, roundtripped))
t.Errorf("diff %s", cmp.Diff(original, roundtripped))
}
}
}

View File

@@ -23,11 +23,11 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
fuzz "github.com/google/gofuzz"
authorizationv1 "k8s.io/api/authorization/v1"
authorizationv1beta1 "k8s.io/api/authorization/v1beta1"
"k8s.io/apimachinery/pkg/util/diff"
)
func TestRoundTrip(t *testing.T) {
@@ -49,7 +49,7 @@ func TestRoundTrip(t *testing.T) {
Status: v1beta1StatusToV1Status(&converted.Status),
}
if !reflect.DeepEqual(original, roundtripped) {
t.Errorf("diff %s", diff.ObjectReflectDiff(original, roundtripped))
t.Errorf("diff %s", cmp.Diff(original, roundtripped))
}
}
}

View File

@@ -34,9 +34,9 @@ import (
"text/template"
"time"
"github.com/google/go-cmp/cmp"
authorizationv1 "k8s.io/api/authorization/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/authorization/authorizer"
@@ -556,7 +556,7 @@ func TestV1Webhook(t *testing.T) {
continue
}
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"
"time"
"github.com/google/go-cmp/cmp"
authorizationv1beta1 "k8s.io/api/authorization/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/authorization/authorizer"
webhookutil "k8s.io/apiserver/pkg/util/webhook"
@@ -548,7 +548,7 @@ func TestV1beta1Webhook(t *testing.T) {
continue
}
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

@@ -8,6 +8,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/evanphx/json-patch v4.12.0+incompatible
github.com/google/gnostic v0.5.7-v3refs
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
github.com/spf13/cobra v1.6.0
@@ -36,7 +37,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect

View File

@@ -21,10 +21,10 @@ import (
"reflect"
"testing"
"k8s.io/api/core/v1"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/client-go/kubernetes/scheme"
)
@@ -74,7 +74,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data
t.Fatal(err)
}
if !reflect.DeepEqual(testData, poutput) {
t.Errorf("Test data and unmarshaled data are not equal: %v", diff.ObjectDiff(poutput, testData))
t.Errorf("Test data and unmarshaled data are not equal: %v", cmp.Diff(poutput, testData))
}
obj := &v1.Pod{
@@ -97,7 +97,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data
t.Fatal(err)
}
if !reflect.DeepEqual(obj, &objOut) {
t.Errorf("Unexpected inequality:\n%v", diff.ObjectDiff(obj, &objOut))
t.Errorf("Unexpected inequality:\n%v", cmp.Diff(obj, &objOut))
}
}

View File

@@ -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))
}
}

View File

@@ -21,12 +21,12 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"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/client-go/dynamic/dynamicinformer"
"k8s.io/client-go/dynamic/fake"
"k8s.io/client-go/tools/cache"
@@ -118,7 +118,7 @@ func TestFilteredDynamicSharedInformerFactory(t *testing.T) {
t.Errorf("informer received an object for namespace %s when watching namespace %s", ts.ns, ts.informNS)
}
if !equality.Semantic.DeepEqual(testObject, objFromInformer) {
t.Fatalf("%v", diff.ObjectDiff(testObject, objFromInformer))
t.Fatalf("%v", cmp.Diff(testObject, objFromInformer))
}
case <-ctx.Done():
if ts.ns == ts.informNS {
@@ -239,7 +239,7 @@ func TestDynamicSharedInformerFactory(t *testing.T) {
select {
case objFromInformer := <-informerReciveObjectCh:
if !equality.Semantic.DeepEqual(testObject, objFromInformer) {
t.Fatalf("%v", diff.ObjectDiff(testObject, objFromInformer))
t.Fatalf("%v", cmp.Diff(testObject, objFromInformer))
}
case <-ctx.Done():
t.Errorf("tested informer haven't received an object, waited %v", timeout)

View File

@@ -20,11 +20,11 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/client-go/dynamic/dynamiclister"
"k8s.io/client-go/tools/cache"
)
@@ -90,7 +90,7 @@ func TestNamespaceGetMethod(t *testing.T) {
t.Fatal(err)
}
if !reflect.DeepEqual(test.expectedObject, actualObject) {
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, diff.ObjectDiff(test.expectedObject, actualObject))
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, cmp.Diff(test.expectedObject, actualObject))
}
})
}
@@ -188,7 +188,7 @@ func TestListerGetMethod(t *testing.T) {
t.Fatal(err)
}
if !reflect.DeepEqual(test.expectedObject, actualObject) {
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, diff.ObjectDiff(test.expectedObject, actualObject))
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, cmp.Diff(test.expectedObject, actualObject))
}
})
}
@@ -245,7 +245,7 @@ func assertListOrDie(expected, actual []*unstructured.Unstructured, t *testing.T
for _, actualObject := range actual {
if actualObject.GetName() == expectedObject.GetName() {
if !reflect.DeepEqual(expectedObject, actualObject) {
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", expectedObject, actualObject, diff.ObjectDiff(expectedObject, actualObject))
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", expectedObject, actualObject, cmp.Diff(expectedObject, actualObject))
}
found = true
}

View File

@@ -28,7 +28,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/diff"
)
const (
@@ -80,7 +79,7 @@ func TestGet(t *testing.T) {
},
}
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{},
}
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) {
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"),
}
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) {
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
}
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
}

View File

@@ -21,12 +21,12 @@ import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/diff"
)
const (
@@ -79,7 +79,7 @@ func TestList(t *testing.T) {
*newPartialObjectMetadata("group/version", "TheKind", "ns-foo", "name-foo"),
}
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
}
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
}

View File

@@ -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))
}
},
},

View File

@@ -22,13 +22,13 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"k8s.io/klog/v2"
"k8s.io/apimachinery/pkg/api/equality"
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/metadata/fake"
"k8s.io/client-go/tools/cache"
)
@@ -147,7 +147,7 @@ func TestMetadataSharedInformerFactory(t *testing.T) {
select {
case objFromInformer := <-informerReciveObjectCh:
if !equality.Semantic.DeepEqual(testObject, objFromInformer) {
t.Fatalf("%v", diff.ObjectDiff(testObject, objFromInformer))
t.Fatalf("%v", cmp.Diff(testObject, objFromInformer))
}
case <-ctx.Done():
t.Errorf("tested informer haven't received an object, waited %v", timeout)

View File

@@ -20,11 +20,11 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/client-go/tools/cache"
)
@@ -89,7 +89,7 @@ func TestNamespaceGetMethod(t *testing.T) {
t.Fatal(err)
}
if !reflect.DeepEqual(test.expectedObject, actualObject) {
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, diff.ObjectDiff(test.expectedObject, actualObject))
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, cmp.Diff(test.expectedObject, actualObject))
}
})
}
@@ -187,7 +187,7 @@ func TestListerGetMethod(t *testing.T) {
t.Fatal(err)
}
if !reflect.DeepEqual(test.expectedObject, actualObject) {
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, diff.ObjectDiff(test.expectedObject, actualObject))
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, cmp.Diff(test.expectedObject, actualObject))
}
})
}
@@ -231,7 +231,7 @@ func assertListOrDie(expected, actual []*metav1.PartialObjectMetadata, t *testin
for _, actualObject := range actual {
if actualObject.GetName() == expectedObject.GetName() {
if !reflect.DeepEqual(expectedObject, actualObject) {
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", expectedObject, actualObject, diff.ObjectDiff(expectedObject, actualObject))
t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", expectedObject, actualObject, cmp.Diff(expectedObject, actualObject))
}
found = true
}

View File

@@ -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))
}
}
}

View File

@@ -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)))
}
}

View File

@@ -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))
}
})
}

View File

@@ -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))
}
}

View File

@@ -23,9 +23,9 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/diff"
testclocks "k8s.io/utils/clock/testing"
)
@@ -121,7 +121,7 @@ func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v
}
recvEvent.Name = expectedEvent.Name
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.LastTimestamp = actualLastTimestamp

View File

@@ -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
}

View File

@@ -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)))
}
})
}

View File

@@ -23,9 +23,9 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/spf13/pflag"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/diff"
apiserver "k8s.io/apiserver/pkg/server"
apiserveroptions "k8s.io/apiserver/pkg/server/options"
appconfig "k8s.io/cloud-provider/app/config"
@@ -150,7 +150,7 @@ func TestDefaultFlags(t *testing.T) {
NodeStatusUpdateFrequency: metav1.Duration{Duration: 5 * time.Minute},
}
if !reflect.DeepEqual(expected, s) {
t.Errorf("Got different run options than expected.\nDifference detected on:\n%s", diff.ObjectReflectDiff(expected, s))
t.Errorf("Got different run options than expected.\nDifference detected on:\n%s", cmp.Diff(expected, s))
}
}
@@ -309,7 +309,7 @@ func TestAddFlags(t *testing.T) {
NodeStatusUpdateFrequency: metav1.Duration{Duration: 10 * time.Minute},
}
if !reflect.DeepEqual(expected, s) {
t.Errorf("Got different run options than expected.\nDifference detected on:\n%s", diff.ObjectReflectDiff(expected, s))
t.Errorf("Got different run options than expected.\nDifference detected on:\n%s", cmp.Diff(expected, s))
}
}
@@ -444,6 +444,6 @@ func TestCreateConfig(t *testing.T) {
c.LoopbackClientConfig = nil
if !reflect.DeepEqual(expected, c) {
t.Errorf("Got different config than expected.\nDifference detected on:\n%s", diff.ObjectReflectDiff(expected, c))
t.Errorf("Got different config than expected.\nDifference detected on:\n%s", cmp.Diff(expected, c))
}
}

View File

@@ -23,6 +23,7 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
coordinationv1 "k8s.io/api/coordination/v1"
corev1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
@@ -31,7 +32,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/diff"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
clienttesting "k8s.io/client-go/testing"
@@ -205,7 +205,7 @@ func TestNewNodeLease(t *testing.T) {
t.Fatalf("the new lease must be newly allocated, but got same address as base")
}
if !apiequality.Semantic.DeepEqual(tc.expect, newLease) {
t.Errorf("unexpected result from newLease: %s", diff.ObjectDiff(tc.expect, newLease))
t.Errorf("unexpected result from newLease: %s", cmp.Diff(tc.expect, newLease))
}
})
}

View File

@@ -19,10 +19,10 @@ package reconciliation
import (
"testing"
"github.com/google/go-cmp/cmp"
rbacv1 "k8s.io/api/rbac/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/diff"
)
func role(rules []rbacv1.PolicyRule, labels map[string]string, annotations map[string]string) *rbacv1.ClusterRole {
@@ -392,7 +392,7 @@ func TestComputeReconciledRoleAggregationRules(t *testing.T) {
continue
}
if reconciliationNeeded && !apiequality.Semantic.DeepEqual(result.Role.(ClusterRoleRuleOwner).ClusterRole, tc.expectedReconciledRole) {
t.Errorf("%s: %v", k, diff.ObjectDiff(tc.expectedReconciledRole, result.Role.(ClusterRoleRuleOwner).ClusterRole))
t.Errorf("%s: %v", k, cmp.Diff(tc.expectedReconciledRole, result.Role.(ClusterRoleRuleOwner).ClusterRole))
}
}
}

View File

@@ -8,6 +8,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/emicklei/go-restful/v3 v3.9.0
github.com/gogo/protobuf v1.3.2
github.com/google/go-cmp v0.5.9
github.com/google/gofuzz v1.1.0
github.com/spf13/cobra v1.6.0
github.com/spf13/pflag v1.0.5
@@ -47,7 +48,6 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.12.6 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect

View File

@@ -23,10 +23,10 @@ import (
"net/http/httputil"
"testing"
"github.com/google/go-cmp/cmp"
apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/cache"
@@ -327,7 +327,7 @@ func TestAPIs(t *testing.T) {
continue
}
if !apiequality.Semantic.DeepEqual(tc.expected, actual) {
t.Errorf("%s: %v", tc.name, diff.ObjectDiff(tc.expected, actual))
t.Errorf("%s: %v", tc.name, cmp.Diff(tc.expected, actual))
continue
}
}
@@ -514,7 +514,7 @@ func TestAPIGroup(t *testing.T) {
continue
}
if !apiequality.Semantic.DeepEqual(tc.expected, actual) {
t.Errorf("%s: %v", tc.name, diff.ObjectDiff(tc.expected, actual))
t.Errorf("%s: %v", tc.name, cmp.Diff(tc.expected, actual))
continue
}
}

View File

@@ -24,8 +24,8 @@ import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
@@ -896,7 +896,7 @@ func (test configCommandTest) run(t *testing.T) string {
testClearLocationOfOrigin(&actualConfig)
if !apiequality.Semantic.DeepEqual(test.expectedConfig, actualConfig) {
t.Errorf("diff: %v", diff.ObjectDiff(test.expectedConfig, actualConfig))
t.Errorf("diff: %v", cmp.Diff(test.expectedConfig, actualConfig))
t.Errorf("expected: %#v\n actual: %#v", test.expectedConfig, actualConfig)
}

View File

@@ -21,7 +21,7 @@ import (
"strings"
"testing"
"k8s.io/apimachinery/pkg/util/diff"
"github.com/google/go-cmp/cmp"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)
@@ -102,7 +102,7 @@ func (test stepParserTest) run(t *testing.T) {
}
if !reflect.DeepEqual(test.expectedNavigationSteps, *actualSteps) {
t.Errorf("diff: %v", diff.ObjectDiff(test.expectedNavigationSteps, *actualSteps))
t.Errorf("diff: %v", cmp.Diff(test.expectedNavigationSteps, *actualSteps))
t.Errorf("expected: %#v\n actual: %#v", test.expectedNavigationSteps, *actualSteps)
}
}

View File

@@ -20,12 +20,12 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
rbac "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "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/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/rest/fake"
@@ -150,7 +150,7 @@ func TestCreateRole(t *testing.T) {
t.Fatal(err)
}
if !equality.Semantic.DeepEqual(test.expectedRole, actual) {
t.Errorf("%s", diff.ObjectReflectDiff(test.expectedRole, actual))
t.Errorf("%s", cmp.Diff(test.expectedRole, actual))
}
})
}

View File

@@ -27,12 +27,12 @@ import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/spf13/cobra"
yaml "gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource"
@@ -124,7 +124,7 @@ func TestEdit(t *testing.T) {
// Convenience to allow recapturing the input and persisting it here
os.WriteFile(inputFile, body, os.FileMode(0644))
} else {
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput)))
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, cmp.Diff(string(body), string(expectedInput)))
t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar)
}
}
@@ -147,7 +147,7 @@ func TestEdit(t *testing.T) {
// Convenience to allow recapturing the input and persisting it here
os.WriteFile(inputFile, body, os.FileMode(0644))
} else {
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput)))
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, cmp.Diff(string(body), string(expectedInput)))
t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar)
}
}

View File

@@ -26,6 +26,7 @@ import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
appsv1 "k8s.io/api/apps/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
batchv1 "k8s.io/api/batch/v1"
@@ -36,7 +37,6 @@ import (
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer/streaming"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource"
@@ -1497,7 +1497,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
}
`
if e, a := expected, buf.String(); e != a {
t.Errorf("did not match: %v", diff.StringDiff(e, a))
t.Errorf("did not match:\n%v", cmp.Diff(e, a))
}
}

View File

@@ -22,6 +22,7 @@ import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
@@ -29,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/kubectl/pkg/scheme"
)
@@ -677,7 +677,7 @@ func TestSortingPrinter(t *testing.T) {
t.Fatalf("%s: expected error containing: %q, got none", tt.name, tt.expectedErr)
}
if !reflect.DeepEqual(table, expectedTable) {
t.Errorf("[%s]\nexpected/saw:\n%s", tt.name, diff.ObjectReflectDiff(expectedTable, table))
t.Errorf("[%s]\nexpected/saw:\n%s", tt.name, cmp.Diff(expectedTable, table))
}
})
t.Run(tt.name, func(t *testing.T) {

View File

@@ -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/validation/field"
"k8s.io/kubectl/pkg/scheme"
"k8s.io/utils/exec"
@@ -155,7 +154,7 @@ func TestMerge(t *testing.T) {
if err != nil {
t.Errorf("testcase[%d], unexpected error: %v", i, err)
} else if !apiequality.Semantic.DeepEqual(test.expected, out) {
t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, diff.ObjectReflectDiff(test.expected, out))
t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, cmp.Diff(test.expected, out))
}
}
if test.expectErr && err == nil {
@@ -238,7 +237,7 @@ func TestStrategicMerge(t *testing.T) {
if err != nil {
t.Errorf("testcase[%d], unexpected error: %v", i, err)
} else if !apiequality.Semantic.DeepEqual(test.expected, out) {
t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, diff.ObjectReflectDiff(test.expected, out))
t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, cmp.Diff(test.expected, out))
}
}
if test.expectErr && err == nil {
@@ -300,7 +299,7 @@ func TestJSONPatch(t *testing.T) {
if err != nil {
t.Errorf("testcase[%d], unexpected error: %v", i, err)
} else if !apiequality.Semantic.DeepEqual(test.expected, out) {
t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, diff.ObjectReflectDiff(test.expected, out))
t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, cmp.Diff(test.expected, out))
}
}
if test.expectErr && err == nil {

View File

@@ -20,7 +20,7 @@ import (
"bytes"
"testing"
"k8s.io/apimachinery/pkg/util/diff"
"github.com/google/go-cmp/cmp"
)
func TestFormatterWrite(t *testing.T) {
@@ -113,7 +113,7 @@ fringilla velit.
`
if buf.String() != want {
t.Errorf("Diff:\n%s", diff.StringDiff(buf.String(), want))
t.Errorf("Diff:\n%s", cmp.Diff(buf.String(), want))
}
}

View File

@@ -22,6 +22,7 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
@@ -29,7 +30,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"
fakeexternal "k8s.io/client-go/kubernetes/fake"
testclient "k8s.io/client-go/testing"
"k8s.io/kubectl/pkg/cmd/util/podcmd"
@@ -422,7 +422,7 @@ func TestLogsForObject(t *testing.T) {
got := fakeClientset.Actions()[i]
want := test.actions[i]
if !reflect.DeepEqual(got, want) {
t.Errorf("%s: unexpected diff for action: %s", test.name, diff.ObjectDiff(got, want))
t.Errorf("%s: unexpected diff for action: %s", test.name, cmp.Diff(got, want))
}
}
for i++; i < len(fakeClientset.Actions()); i++ {

View File

@@ -19,11 +19,11 @@ package scheme
import (
"testing"
"k8s.io/api/batch/v1"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff"
)
func TestCronJob(t *testing.T) {
@@ -48,6 +48,6 @@ func TestCronJob(t *testing.T) {
uncastDst.(*v1.CronJob).TypeMeta = metav1.TypeMeta{}
if !equality.Semantic.DeepEqual(src, uncastDst) {
t.Fatal(diff.ObjectDiff(src, uncastDst))
t.Fatal(cmp.Diff(src, uncastDst))
}
}

View File

@@ -24,9 +24,9 @@ import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/pod-security-admission/api"
@@ -167,7 +167,7 @@ func testFixtureFile(t *testing.T, dir, name string, pod *corev1.Pod) string {
t.Logf("Could not update data in %s: %v", filename, err)
}
} else {
t.Logf("Diff between generated data and fixture data in %s:\n-------------\n%s", filename, diff.StringDiff(string(yamlData), string(expectedYAML)))
t.Logf("Diff between generated data and fixture data in %s:\n-------------\n%s", filename, cmp.Diff(string(yamlData), string(expectedYAML)))
t.Logf("If the change is expected, re-run with %s=true to update the fixtures", updateEnvVar)
}
}