From d556d913f887e0214d074b1993c07887f4e693e4 Mon Sep 17 00:00:00 2001 From: DiptoChakrabarty Date: Sat, 11 Mar 2023 20:03:04 +0530 Subject: [PATCH] replace reflect deepequal in bootstrap kubeadm --- .../api/v1alpha4/kubeadm_types_test.go | 7 +++--- .../kubeadm/api/v1beta1/kubeadm_types_test.go | 7 +++--- .../bootstraptokenstring_test.go | 7 +++--- .../bootstraptokenstring_test.go | 7 +++--- .../bootstraptokenstring_test.go | 22 +++++++++++-------- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/bootstrap/kubeadm/api/v1alpha4/kubeadm_types_test.go b/bootstrap/kubeadm/api/v1alpha4/kubeadm_types_test.go index b0c9a858e92d..0173e0d6e111 100644 --- a/bootstrap/kubeadm/api/v1alpha4/kubeadm_types_test.go +++ b/bootstrap/kubeadm/api/v1alpha4/kubeadm_types_test.go @@ -18,9 +18,9 @@ package v1alpha4 import ( "encoding/json" - "reflect" "testing" + "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" "github.com/pkg/errors" ) @@ -119,11 +119,12 @@ func roundtrip(input string, bts *BootstrapTokenString) error { if err := json.Unmarshal(b, newbts); err != nil { return errors.Wrap(err, "expected no unmarshal error, got error") } - if !reflect.DeepEqual(bts, newbts) { + if diff := cmp.Diff(bts, newbts); diff != "" { return errors.Errorf( - "expected object: %v\n\t actual: %v", + "expected object: %v\n\t actual: %v\n\t got diff: %v", bts, newbts, + diff, ) } } diff --git a/bootstrap/kubeadm/api/v1beta1/kubeadm_types_test.go b/bootstrap/kubeadm/api/v1beta1/kubeadm_types_test.go index 508263a039f4..8a0d6f197093 100644 --- a/bootstrap/kubeadm/api/v1beta1/kubeadm_types_test.go +++ b/bootstrap/kubeadm/api/v1beta1/kubeadm_types_test.go @@ -18,9 +18,9 @@ package v1beta1 import ( "encoding/json" - "reflect" "testing" + "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" @@ -177,11 +177,12 @@ func roundtrip(input string, bts *BootstrapTokenString) error { if err := json.Unmarshal(b, newbts); err != nil { return errors.Wrap(err, "expected no unmarshal error, got error") } - if !reflect.DeepEqual(bts, newbts) { + if diff := cmp.Diff(bts, newbts); diff != "" { return errors.Errorf( - "expected object: %v\n\t actual: %v", + "expected object: %v\n\t actual: %v\n\t got diff: %v", bts, newbts, + diff, ) } } diff --git a/bootstrap/kubeadm/types/upstreamv1beta1/bootstraptokenstring_test.go b/bootstrap/kubeadm/types/upstreamv1beta1/bootstraptokenstring_test.go index 3a723e74f999..ce7f45252321 100644 --- a/bootstrap/kubeadm/types/upstreamv1beta1/bootstraptokenstring_test.go +++ b/bootstrap/kubeadm/types/upstreamv1beta1/bootstraptokenstring_test.go @@ -18,9 +18,9 @@ package upstreamv1beta1 import ( "encoding/json" - "reflect" "testing" + "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" "github.com/pkg/errors" ) @@ -119,11 +119,12 @@ func roundtrip(input string, bts *BootstrapTokenString) error { if err := json.Unmarshal(b, newbts); err != nil { return errors.Wrap(err, "expected no unmarshal error, got error") } - if !reflect.DeepEqual(bts, newbts) { + if diff := cmp.Diff(bts, newbts); diff != "" { return errors.Errorf( - "expected object: %v\n\t actual: %v", + "expected object: %v\n\t actual: %v\n\t got diff: %v", bts, newbts, + diff, ) } } diff --git a/bootstrap/kubeadm/types/upstreamv1beta2/bootstraptokenstring_test.go b/bootstrap/kubeadm/types/upstreamv1beta2/bootstraptokenstring_test.go index 56f1e1d38d10..3a0d1b5331ba 100644 --- a/bootstrap/kubeadm/types/upstreamv1beta2/bootstraptokenstring_test.go +++ b/bootstrap/kubeadm/types/upstreamv1beta2/bootstraptokenstring_test.go @@ -18,9 +18,9 @@ package upstreamv1beta2 import ( "encoding/json" - "reflect" "testing" + "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" "github.com/pkg/errors" ) @@ -119,11 +119,12 @@ func roundtrip(input string, bts *BootstrapTokenString) error { if err := json.Unmarshal(b, newbts); err != nil { return errors.Wrap(err, "expected no unmarshal error, got error") } - if !reflect.DeepEqual(bts, newbts) { + if diff := cmp.Diff(bts, newbts); diff != "" { return errors.Errorf( - "expected object: %v\n\t actual: %v", + "expected object: %v\n\t actual: %v\n\t got diff: %v", bts, newbts, + diff, ) } } diff --git a/bootstrap/kubeadm/types/upstreamv1beta3/bootstraptokenstring_test.go b/bootstrap/kubeadm/types/upstreamv1beta3/bootstraptokenstring_test.go index b19e652b0671..640c581a6dea 100644 --- a/bootstrap/kubeadm/types/upstreamv1beta3/bootstraptokenstring_test.go +++ b/bootstrap/kubeadm/types/upstreamv1beta3/bootstraptokenstring_test.go @@ -18,9 +18,9 @@ package upstreamv1beta3 import ( "encoding/json" - "reflect" "testing" + "github.com/google/go-cmp/cmp" "github.com/pkg/errors" ) @@ -71,11 +71,12 @@ func TestUnmarshalJSON(t *testing.T) { err := json.Unmarshal([]byte(rt.input), newbts) if (err != nil) != rt.expectedError { t.Errorf("failed BootstrapTokenString.UnmarshalJSON:\n\texpected error: %t\n\t actual error: %v", rt.expectedError, err) - } else if !reflect.DeepEqual(rt.bts, newbts) { + } else if diff := cmp.Diff(rt.bts, newbts); diff != "" { t.Errorf( - "failed BootstrapTokenString.UnmarshalJSON:\n\texpected: %v\n\t actual: %v", + "failed BootstrapTokenString.UnmarshalJSON:\n\texpected: %v\n\t actual: %v\n\t diff: %v", rt.bts, newbts, + diff, ) } }) @@ -125,11 +126,12 @@ func roundtrip(input string, bts *BootstrapTokenString) error { if err := json.Unmarshal(b, newbts); err != nil { return errors.Wrap(err, "expected no unmarshal error, got error") } - if !reflect.DeepEqual(bts, newbts) { + if diff := cmp.Diff(bts, newbts); diff != "" { return errors.Errorf( - "expected object: %v\n\t actual: %v", + "expected object: %v\n\t actual: %v\n\t got diff: %v", bts, newbts, + diff, ) } } @@ -192,12 +194,13 @@ func TestNewBootstrapTokenString(t *testing.T) { rt.expectedError, err, ) - } else if !reflect.DeepEqual(actual, rt.bts) { + } else if diff := cmp.Diff(actual, rt.bts); diff != "" { t.Errorf( - "failed NewBootstrapTokenString for the token %q\n\texpected: %v\n\t actual: %v", + "failed NewBootstrapTokenString for the token %q\n\texpected: %v\n\t actual: %v\n\t diff: %v", rt.token, rt.bts, actual, + diff, ) } }) @@ -235,13 +238,14 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) { rt.expectedError, err, ) - } else if !reflect.DeepEqual(actual, rt.bts) { + } else if diff := cmp.Diff(actual, rt.bts); diff != "" { t.Errorf( - "failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q\n\texpected: %v\n\t actual: %v", + "failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q\n\texpected: %v\n\t actual: %v\n\t diff: %v", rt.id, rt.secret, rt.bts, actual, + diff, ) } })