Skip to content

Commit

Permalink
replace reflect deepequal in bootstrap kubeadm
Browse files Browse the repository at this point in the history
  • Loading branch information
DiptoChakrabarty committed Mar 11, 2023
1 parent 899b324 commit d556d91
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
7 changes: 4 additions & 3 deletions bootstrap/kubeadm/api/v1alpha4/kubeadm_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
)
}
}
Expand Down
7 changes: 4 additions & 3 deletions bootstrap/kubeadm/api/v1beta1/kubeadm_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package upstreamv1beta3

import (
"encoding/json"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/pkg/errors"
)

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

0 comments on commit d556d91

Please sign in to comment.