From 1ae57e8e9a824fd3a2e1da884a2f01152ed54d9a Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Sat, 19 Aug 2023 21:28:59 -0700 Subject: [PATCH] WIP: Switch to using cmpopts.EquateErrors Signed-off-by: Nic Cope --- pkg/certificates/certificates.go | 12 +--- pkg/certificates/certificates_test.go | 20 +++--- pkg/connection/manager.go | 38 ++++------- pkg/connection/manager_test.go | 66 +++++++++++-------- pkg/connection/store/kubernetes/store.go | 28 +++----- pkg/connection/store/kubernetes/store_test.go | 28 ++++---- pkg/connection/store/plugin/store.go | 17 ++--- pkg/connection/store/plugin/store_test.go | 14 ++-- pkg/connection/stores.go | 6 +- pkg/controller/engine_test.go | 6 +- pkg/errors/errors_test.go | 9 ++- pkg/fieldpath/fieldpath_test.go | 4 +- pkg/fieldpath/merge_test.go | 4 +- pkg/fieldpath/paved_test.go | 21 +++--- pkg/meta/meta_test.go | 4 +- pkg/parser/linter_test.go | 6 +- pkg/ratelimiter/reconciler_test.go | 5 +- pkg/reconciler/managed/api_test.go | 9 +-- pkg/reconciler/managed/publisher_test.go | 8 +-- pkg/reconciler/managed/reconciler_test.go | 4 +- .../providerconfig/reconciler_test.go | 3 +- pkg/reference/reference_test.go | 4 +- pkg/resource/api_test.go | 9 +-- pkg/resource/providerconfig_test.go | 9 +-- pkg/resource/resource_test.go | 16 ++--- pkg/resource/unstructured/client_test.go | 21 +++--- pkg/webhook/mutator_test.go | 5 +- pkg/webhook/validator_test.go | 7 +- 28 files changed, 175 insertions(+), 208 deletions(-) diff --git a/pkg/certificates/certificates.go b/pkg/certificates/certificates.go index e4f3c1d05..1e54b19ff 100644 --- a/pkg/certificates/certificates.go +++ b/pkg/certificates/certificates.go @@ -26,30 +26,24 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/errors" ) -const ( - errLoadCert = "cannot load certificate" - errLoadCA = "cannot load CA certificate" - errInvalidCA = "invalid CA certificate" -) - // LoadMTLSConfig loads TLS certificates in the given folder using well-defined filenames for certificates in a Kubernetes environment. func LoadMTLSConfig(caPath, certPath, keyPath string, isServer bool) (*tls.Config, error) { tlsCertFilePath := filepath.Clean(certPath) tlsKeyFilePath := filepath.Clean(keyPath) certificate, err := tls.LoadX509KeyPair(tlsCertFilePath, tlsKeyFilePath) if err != nil { - return nil, errors.Wrap(err, errLoadCert) + return nil, errors.Wrap(err, "cannot load certificate") } caCertFilePath := filepath.Clean(caPath) ca, err := os.ReadFile(caCertFilePath) if err != nil { - return nil, errors.Wrap(err, errLoadCA) + return nil, errors.Wrap(err, "cannot load CA certificate") } pool := x509.NewCertPool() if !pool.AppendCertsFromPEM(ca) { - return nil, errors.New(errInvalidCA) + return nil, errors.New("invalid CA certificate") } tlsConfig := &tls.Config{ diff --git a/pkg/certificates/certificates_test.go b/pkg/certificates/certificates_test.go index 3c854f57d..8017b768f 100644 --- a/pkg/certificates/certificates_test.go +++ b/pkg/certificates/certificates_test.go @@ -2,18 +2,12 @@ package certificates import ( "crypto/tls" + "os" "path/filepath" "testing" "github.com/google/go-cmp/cmp" - - "github.com/crossplane/crossplane-runtime/pkg/errors" - "github.com/crossplane/crossplane-runtime/pkg/test" -) - -var ( - errNoSuchFile = errors.New("open invalid/path/tls.crt: no such file or directory") - errNoCAFile = errors.New("open test-data/no-ca/ca.crt: no such file or directory") + "github.com/google/go-cmp/cmp/cmpopts" ) const ( @@ -42,7 +36,7 @@ func TestLoad(t *testing.T) { certsFolderPath: "invalid/path", }, want: want{ - err: errors.Wrap(errNoSuchFile, errLoadCert), + err: os.ErrNotExist, out: nil, }, }, @@ -52,7 +46,7 @@ func TestLoad(t *testing.T) { certsFolderPath: "test-data/no-ca", }, want: want{ - err: errors.Wrap(errNoCAFile, errLoadCA), + err: os.ErrNotExist, out: nil, }, }, @@ -62,7 +56,9 @@ func TestLoad(t *testing.T) { certsFolderPath: "test-data/invalid-certs/", }, want: want{ - err: errors.New(errInvalidCA), + // TODO(negz): Can we be more specific? Should we use a sentinel + // error? + err: cmpopts.AnyError, out: nil, }, }, @@ -96,7 +92,7 @@ func TestLoad(t *testing.T) { requireClient := tc.args.requireClientValidation cfg, err := LoadMTLSConfig(filepath.Join(certsFolderPath, caCertFileName), filepath.Join(certsFolderPath, tlsCertFileName), filepath.Join(certsFolderPath, tlsKeyFileName), requireClient) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nLoad(...): -want error, +got error:\n%s", tc.reason, diff) } diff --git a/pkg/connection/manager.go b/pkg/connection/manager.go index 3bc017187..e5f512500 100644 --- a/pkg/connection/manager.go +++ b/pkg/connection/manager.go @@ -33,18 +33,6 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/resource" ) -// Error strings. -const ( - errConnectStore = "cannot connect to secret store" - errWriteStore = "cannot write to secret store" - errReadStore = "cannot read from secret store" - errDeleteFromStore = "cannot delete from secret store" - errGetStoreConfig = "cannot get store config" - errSecretConflict = "cannot establish control of existing connection secret" - - errFmtNotOwnedBy = "existing secret is not owned by UID %q" -) - // StoreBuilderFn is a function that builds and returns a Store with a given // store config. type StoreBuilderFn func(ctx context.Context, local client.Client, tcfg *tls.Config, cfg v1.SecretStoreConfig) (Store, error) @@ -110,11 +98,11 @@ func (m *DetailsManager) PublishConnection(ctx context.Context, so resource.Conn ss, err := m.connectStore(ctx, p) if err != nil { - return false, errors.Wrap(err, errConnectStore) + return false, errors.Wrap(err, "cannot connect to secret store") } changed, err := ss.WriteKeyValues(ctx, store.NewSecret(so, store.KeyValues(conn)), SecretToWriteMustBeOwnedBy(so)) - return changed, errors.Wrap(err, errWriteStore) + return changed, errors.Wrap(err, "cannot write to secret store") } // UnpublishConnection deletes connection details secret to the configured @@ -128,10 +116,10 @@ func (m *DetailsManager) UnpublishConnection(ctx context.Context, so resource.Co ss, err := m.connectStore(ctx, p) if err != nil { - return errors.Wrap(err, errConnectStore) + return errors.Wrap(err, "cannot connect to secret store") } - return errors.Wrap(ss.DeleteKeyValues(ctx, store.NewSecret(so, store.KeyValues(conn)), SecretToDeleteMustBeOwnedBy(so)), errDeleteFromStore) + return errors.Wrap(ss.DeleteKeyValues(ctx, store.NewSecret(so, store.KeyValues(conn)), SecretToDeleteMustBeOwnedBy(so)), "cannot delete from secret store") } // FetchConnection fetches connection details of a given ConnectionSecretOwner. @@ -144,11 +132,11 @@ func (m *DetailsManager) FetchConnection(ctx context.Context, so resource.Connec ss, err := m.connectStore(ctx, p) if err != nil { - return nil, errors.Wrap(err, errConnectStore) + return nil, errors.Wrap(err, "cannot connect to secret store") } s := &store.Secret{} - return managed.ConnectionDetails(s.Data), errors.Wrap(ss.ReadKeyValues(ctx, store.ScopedName{Name: p.Name, Scope: so.GetNamespace()}, s), errReadStore) + return managed.ConnectionDetails(s.Data), errors.Wrap(ss.ReadKeyValues(ctx, store.ScopedName{Name: p.Name, Scope: so.GetNamespace()}, s), "cannot read from secret store") } // PropagateConnection propagate connection details from one resource to another. @@ -160,7 +148,7 @@ func (m *DetailsManager) PropagateConnection(ctx context.Context, to resource.Lo ssFrom, err := m.connectStore(ctx, from.GetPublishConnectionDetailsTo()) if err != nil { - return false, errors.Wrap(err, errConnectStore) + return false, errors.Wrap(err, "cannot connect to secret store") } sFrom := &store.Secret{} @@ -168,29 +156,29 @@ func (m *DetailsManager) PropagateConnection(ctx context.Context, to resource.Lo Name: from.GetPublishConnectionDetailsTo().Name, Scope: from.GetNamespace(), }, sFrom); err != nil { - return false, errors.Wrap(err, errReadStore) + return false, errors.Wrap(err, "cannot read from secret store") } // Make sure 'from' is the controller of the connection secret it references // before we propagate it. This ensures a resource cannot use Crossplane to // circumvent RBAC by propagating a secret it does not own. if sFrom.GetOwner() != string(from.GetUID()) { - return false, errors.New(errSecretConflict) + return false, errors.New("cannot establish control of existing connection secret") } ssTo, err := m.connectStore(ctx, to.GetPublishConnectionDetailsTo()) if err != nil { - return false, errors.Wrap(err, errConnectStore) + return false, errors.Wrap(err, "cannot connect to secret store") } changed, err := ssTo.WriteKeyValues(ctx, store.NewSecret(to, sFrom.Data), SecretToWriteMustBeOwnedBy(to)) - return changed, errors.Wrap(err, errWriteStore) + return changed, errors.Wrap(err, "cannot write to secret store") } func (m *DetailsManager) connectStore(ctx context.Context, p *v1.PublishConnectionDetailsTo) (Store, error) { sc := m.newConfig() if err := m.client.Get(ctx, types.NamespacedName{Name: p.SecretStoreConfigRef.Name}, sc); err != nil { - return nil, errors.Wrap(err, errGetStoreConfig) + return nil, errors.Wrap(err, "cannot get store config") } return m.storeBuilder(ctx, m.client, m.tcfg, sc.GetStoreConfig()) @@ -214,7 +202,7 @@ func SecretToDeleteMustBeOwnedBy(so metav1.Object) store.DeleteOption { func secretMustBeOwnedBy(so metav1.Object, secret *store.Secret) error { if secret.Metadata == nil || secret.Metadata.GetOwnerUID() != string(so.GetUID()) { - return errors.Errorf(errFmtNotOwnedBy, string(so.GetUID())) + return errors.Errorf("existing secret is not woned by UID %q", string(so.GetUID())) } return nil } diff --git a/pkg/connection/manager_test.go b/pkg/connection/manager_test.go index d5da750f6..c04cf8d0a 100644 --- a/pkg/connection/manager_test.go +++ b/pkg/connection/manager_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" @@ -43,10 +44,6 @@ const ( testUID = "e8587e99-15c9-4069-a530-1d2205032848" ) -const ( - errBuildStore = "cannot build store" -) - var ( fakeStore = secretStoreFake @@ -87,7 +84,8 @@ func TestManagerConnectStore(t *testing.T) { }, }, want: want{ - err: errors.Wrapf(kerrors.NewNotFound(schema.GroupResource{}, fakeConfig), errGetStoreConfig), + // TODO(negz): Can we test that this is kerrors.NewNotFound? + err: cmpopts.AnyError, }, }, "BuildStoreError": { @@ -101,7 +99,7 @@ func TestManagerConnectStore(t *testing.T) { MockScheme: test.NewMockSchemeFn(resourcefake.SchemeWith(&fake.StoreConfig{})), }, sb: func(ctx context.Context, local client.Client, tCfg *tls.Config, cfg v1.SecretStoreConfig) (Store, error) { - return nil, errors.New(errBuildStore) + return nil, errBoom }, p: &v1.PublishConnectionDetailsTo{ SecretStoreConfigRef: &v1.Reference{ @@ -110,7 +108,7 @@ func TestManagerConnectStore(t *testing.T) { }, }, want: want{ - err: errors.New(errBuildStore), + err: errBoom, }, }, "SuccessfulConnect": { @@ -147,7 +145,7 @@ func TestManagerConnectStore(t *testing.T) { m := NewDetailsManager(tc.args.c, resourcefake.GVK(&fake.StoreConfig{}), WithStoreBuilder(tc.args.sb)) _, err := m.connectStore(context.Background(), tc.args.p) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nReason: %s\nm.connectStore(...): -want error, +got error:\n%s", tc.reason, diff) } }) @@ -208,7 +206,8 @@ func TestManagerPublishConnection(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.Wrapf(kerrors.NewNotFound(schema.GroupResource{}, "non-existing"), errGetStoreConfig), errConnectStore), + // TODO(negz): Can we test that this is kerrors.NewNotFound? + err: cmpopts.AnyError, }, }, "CannotPublishTo": { @@ -242,7 +241,7 @@ func TestManagerPublishConnection(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errBoom, errWriteStore), + err: errBoom, }, }, "SuccessfulPublishWithOwnerUID": { @@ -292,7 +291,7 @@ func TestManagerPublishConnection(t *testing.T) { m := NewDetailsManager(tc.args.c, resourcefake.GVK(&fake.StoreConfig{}), WithStoreBuilder(tc.args.sb)) published, err := m.PublishConnection(context.Background(), tc.args.so, tc.args.conn) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nReason: %s\nm.publishConnection(...): -want error, +got error:\n%s", tc.reason, diff) } if diff := cmp.Diff(tc.want.published, published); diff != "" { @@ -355,7 +354,8 @@ func TestManagerUnpublishConnection(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.Wrapf(kerrors.NewNotFound(schema.GroupResource{}, "non-existing"), errGetStoreConfig), errConnectStore), + // TODO(negz): Can we test that this is kerrors.NewNotFound? + err: cmpopts.AnyError, }, }, "CannotUnpublish": { @@ -389,7 +389,7 @@ func TestManagerUnpublishConnection(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errBoom, errDeleteFromStore), + err: errBoom, }, }, "CannotUnpublishUnowned": { @@ -436,7 +436,8 @@ func TestManagerUnpublishConnection(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.Errorf(errFmtNotOwnedBy, testUID), errDeleteFromStore), + // TODO(negz): Can we be more specific? + err: cmpopts.AnyError, }, }, "SuccessfulUnpublish": { @@ -492,7 +493,7 @@ func TestManagerUnpublishConnection(t *testing.T) { m := NewDetailsManager(tc.args.c, resourcefake.GVK(&fake.StoreConfig{}), WithStoreBuilder(tc.args.sb)) err := m.UnpublishConnection(context.Background(), tc.args.so, tc.args.conn) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nReason: %s\nm.unpublishConnection(...): -want error, +got error:\n%s", tc.reason, diff) } }) @@ -552,7 +553,8 @@ func TestManagerFetchConnection(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.Wrapf(kerrors.NewNotFound(schema.GroupResource{}, "non-existing"), errGetStoreConfig), errConnectStore), + // TODO(negz): Can we test that this is kerrors.NewNotFound? + err: cmpopts.AnyError, }, }, "CannotFetch": { @@ -586,7 +588,7 @@ func TestManagerFetchConnection(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errBoom, errReadStore), + err: errBoom, }, }, "SuccessfulFetch": { @@ -635,7 +637,7 @@ func TestManagerFetchConnection(t *testing.T) { m := NewDetailsManager(tc.args.c, resourcefake.GVK(&fake.StoreConfig{}), WithStoreBuilder(tc.args.sb)) got, err := m.FetchConnection(context.Background(), tc.args.so) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nReason: %s\nm.FetchConnection(...): -want error, +got error:\n%s", tc.reason, diff) } if diff := cmp.Diff(tc.want.conn, got); diff != "" { @@ -713,7 +715,8 @@ func TestManagerPropagateConnection(t *testing.T) { to: &resourcefake.MockLocalConnectionSecretOwner{To: &v1.PublishConnectionDetailsTo{}}, }, want: want{ - err: errors.Wrap(errors.Wrapf(kerrors.NewNotFound(schema.GroupResource{}, "non-existing"), errGetStoreConfig), errConnectStore), + // TODO(negz): Can we test that this is kerrors.NewNotFound? + err: cmpopts.AnyError, }, }, "CannotFetch": { @@ -748,7 +751,7 @@ func TestManagerPropagateConnection(t *testing.T) { to: &resourcefake.MockLocalConnectionSecretOwner{To: &v1.PublishConnectionDetailsTo{}}, }, want: want{ - err: errors.Wrap(errBoom, errReadStore), + err: errBoom, }, }, "CannotEstablishControlOfUnowned": { @@ -798,7 +801,9 @@ func TestManagerPropagateConnection(t *testing.T) { }, }, want: want{ - err: errors.New(errSecretConflict), + // TODO(negz): Can we be more specific? Do we want a sentinel + // error? + err: cmpopts.AnyError, }, }, "CannotEstablishControlOfAnotherOwner": { @@ -852,7 +857,9 @@ func TestManagerPropagateConnection(t *testing.T) { }, }, want: want{ - err: errors.New(errSecretConflict), + // TODO(negz): Can we be more specific? Do we want a sentinel + // error? + err: cmpopts.AnyError, }, }, "CannotConnectDestination": { @@ -906,7 +913,8 @@ func TestManagerPropagateConnection(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.Wrapf(kerrors.NewNotFound(schema.GroupResource{}, "non-existing"), errGetStoreConfig), errConnectStore), + // TODO(negz): Can we test that this is kerrors.NewNotFound? + err: cmpopts.AnyError, }, }, "CannotPublish": { @@ -958,7 +966,7 @@ func TestManagerPropagateConnection(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errBoom, errWriteStore), + err: errBoom, }, }, "DestinationSecretCannotBeOwned": { @@ -1024,7 +1032,8 @@ func TestManagerPropagateConnection(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.Errorf(errFmtNotOwnedBy, testUID), errWriteStore), + // TODO(negz): Can we be more specific? + err: cmpopts.AnyError, }, }, "SuccessfulPropagateCreated": { @@ -1138,7 +1147,8 @@ func TestManagerPropagateConnection(t *testing.T) { }, want: want{ propagated: false, - err: errors.Wrap(errors.Errorf(errFmtNotOwnedBy, ""), errWriteStore), + // TODO(negz): Can we be more specific? + err: cmpopts.AnyError, }, }, "SuccessfulPropagateUpdated": { @@ -1216,7 +1226,7 @@ func TestManagerPropagateConnection(t *testing.T) { m := NewDetailsManager(tc.args.c, resourcefake.GVK(&fake.StoreConfig{}), WithStoreBuilder(tc.args.sb)) got, err := m.PropagateConnection(context.Background(), tc.args.to, tc.args.from) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nReason: %s\nm.PropagateConnection(...): -want error, +got error:\n%s", tc.reason, diff) } if diff := cmp.Diff(tc.want.propagated, got); diff != "" { @@ -1231,6 +1241,6 @@ func fakeStoreBuilderFn(ss fake.SecretStore) StoreBuilderFn { if *cfg.Type == fakeStore { return &ss, nil } - return nil, errors.Errorf(errFmtUnknownSecretStore, *cfg.Type) + return nil, errors.Errorf("unknown secret store type: %q", *cfg.Type) } } diff --git a/pkg/connection/store/kubernetes/store.go b/pkg/connection/store/kubernetes/store.go index 72623efb7..bc6b6d778 100644 --- a/pkg/connection/store/kubernetes/store.go +++ b/pkg/connection/store/kubernetes/store.go @@ -37,18 +37,6 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/resource" ) -// Error strings. -const ( - errGetSecret = "cannot get secret" - errDeleteSecret = "cannot delete secret" - errUpdateSecret = "cannot update secret" - errApplySecret = "cannot apply secret" - - errExtractKubernetesAuthCreds = "cannot extract kubernetes auth credentials" - errBuildRestConfig = "cannot build rest config kubeconfig" - errBuildClient = "cannot build Kubernetes client" -) - // SecretStore is a Kubernetes Secret Store. type SecretStore struct { client resource.ClientApplicator @@ -60,7 +48,7 @@ type SecretStore struct { func NewSecretStore(ctx context.Context, local client.Client, _ *tls.Config, cfg v1.SecretStoreConfig) (*SecretStore, error) { kube, err := buildClient(ctx, local, cfg) if err != nil { - return nil, errors.Wrap(err, errBuildClient) + return nil, errors.Wrap(err, "cannot build Kubernetes client") } return &SecretStore{ @@ -81,11 +69,11 @@ func buildClient(ctx context.Context, local client.Client, cfg v1.SecretStoreCon // Configure client for an external API server with a given Kubeconfig. kfg, err := resource.CommonCredentialExtractor(ctx, cfg.Kubernetes.Auth.Source, local, cfg.Kubernetes.Auth.CommonCredentialSelectors) if err != nil { - return nil, errors.Wrap(err, errExtractKubernetesAuthCreds) + return nil, errors.Wrap(err, "cannot extract Kubernetes auth credentials") } config, err := clientcmd.RESTConfigFromKubeConfig(kfg) if err != nil { - return nil, errors.Wrap(err, errBuildRestConfig) + return nil, errors.Wrap(err, "cannot build REST config kubeconfig") } return client.New(config, client.Options{}) } @@ -94,7 +82,7 @@ func buildClient(ctx context.Context, local client.Client, cfg v1.SecretStoreCon func (ss *SecretStore) ReadKeyValues(ctx context.Context, n store.ScopedName, s *store.Secret) error { ks := &corev1.Secret{} if err := ss.client.Get(ctx, types.NamespacedName{Name: n.Name, Namespace: ss.namespaceForSecret(n)}, ks); resource.IgnoreNotFound(err) != nil { - return errors.Wrap(err, errGetSecret) + return errors.Wrap(err, "cannot get secret") } s.Data = ks.Data s.Metadata = &v1.ConnectionSecretMetadata{ @@ -137,7 +125,7 @@ func (ss *SecretStore) WriteKeyValues(ctx context.Context, s *store.Secret, wo . return false, nil } if err != nil { - return false, errors.Wrap(err, errApplySecret) + return false, errors.Wrap(err, "cannot apply secret") } return true, nil } @@ -162,7 +150,7 @@ func (ss *SecretStore) DeleteKeyValues(ctx context.Context, s *store.Secret, do return nil } if err != nil { - return errors.Wrap(err, errGetSecret) + return errors.Wrap(err, "cannot get secret") } for _, o := range do { @@ -179,10 +167,10 @@ func (ss *SecretStore) DeleteKeyValues(ctx context.Context, s *store.Secret, do // Secret is deleted only if: // - No kv to delete specified as input // - No data left in the secret - return errors.Wrapf(ss.client.Delete(ctx, ks), errDeleteSecret) + return errors.Wrapf(ss.client.Delete(ctx, ks), "cannot delete secret") } // If there are still keys left, update the secret with the remaining. - return errors.Wrapf(ss.client.Update(ctx, ks), errUpdateSecret) + return errors.Wrapf(ss.client.Update(ctx, ks), "cannot update secret") } func (ss *SecretStore) namespaceForSecret(n store.ScopedName) string { diff --git a/pkg/connection/store/kubernetes/store_test.go b/pkg/connection/store/kubernetes/store_test.go index b5afd10e8..c5f25f2ca 100644 --- a/pkg/connection/store/kubernetes/store_test.go +++ b/pkg/connection/store/kubernetes/store_test.go @@ -21,6 +21,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" corev1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -94,7 +95,7 @@ func TestSecretStoreReadKeyValues(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errBoom, errGetSecret), + err: errBoom, }, }, "SuccessfulRead": { @@ -145,7 +146,7 @@ func TestSecretStoreReadKeyValues(t *testing.T) { s := &store.Secret{} s.ScopedName = tc.args.n err := ss.ReadKeyValues(context.Background(), tc.args.n, s) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nss.ReadKeyValues(...): -want error, +got error:\n%s", tc.reason, diff) } @@ -192,7 +193,7 @@ func TestSecretStoreWriteKeyValues(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errBoom, errApplySecret), + err: errBoom, }, }, "FailedWriteOption": { @@ -222,7 +223,7 @@ func TestSecretStoreWriteKeyValues(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errBoom, errApplySecret), + err: errBoom, }, }, "SuccessfulWriteOption": { @@ -469,7 +470,7 @@ func TestSecretStoreWriteKeyValues(t *testing.T) { defaultNamespace: tc.args.defaultNamespace, } changed, err := ss.WriteKeyValues(context.Background(), tc.args.secret, tc.args.wo...) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nss.WriteKeyValues(...): -want error, +got error:\n%s", tc.reason, diff) } if diff := cmp.Diff(tc.want.changed, changed); diff != "" { @@ -512,7 +513,7 @@ func TestSecretStoreDeleteKeyValues(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errBoom, errGetSecret), + err: errBoom, }, }, "SecretUpdatedWithRemainingKeys": { @@ -567,7 +568,7 @@ func TestSecretStoreDeleteKeyValues(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errBoom, errDeleteSecret), + err: errBoom, }, }, "SecretAlreadyDeleted": { @@ -659,7 +660,7 @@ func TestSecretStoreDeleteKeyValues(t *testing.T) { defaultNamespace: tc.args.defaultNamespace, } err := ss.DeleteKeyValues(context.Background(), tc.args.secret, tc.args.do...) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nss.DeleteKeyValues(...): -want error, +got error:\n%s", tc.reason, diff) } }) @@ -723,7 +724,8 @@ func TestNewSecretStore(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.Wrap(errors.Wrap(kerrors.NewNotFound(schema.GroupResource{}, "kube-conn"), "cannot get credentials secret"), errExtractKubernetesAuthCreds), errBuildClient), + // TODO(negz): Can we test that this is a *kerrors.StatusError? + err: cmpopts.AnyError, }, }, "InvalidRestConfigForRemote": { @@ -769,7 +771,8 @@ malformed }, }, want: want{ - err: errors.Wrap(errors.Wrap(errors.New("yaml: line 5: could not find expected ':'"), errBuildRestConfig), errBuildClient), + // TODO(negz): Can we be more specific? + err: cmpopts.AnyError, }, }, "InvalidKubeconfigForRemote": { @@ -829,7 +832,8 @@ users: }, }, want: want{ - err: errors.Wrap(errors.New("unable to load root certificates: unable to parse bytes as PEM block"), errBuildClient), + // TODO(negz): Can we be more specific? + err: cmpopts.AnyError, }, }, } @@ -837,7 +841,7 @@ users: for name, tc := range cases { t.Run(name, func(t *testing.T) { _, err := NewSecretStore(context.Background(), tc.args.client, nil, tc.args.cfg) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nNewSecretStore(...): -want error, +got error:\n%s", tc.reason, diff) } }) diff --git a/pkg/connection/store/plugin/store.go b/pkg/connection/store/plugin/store.go index fa6b3078c..cbec36a43 100644 --- a/pkg/connection/store/plugin/store.go +++ b/pkg/connection/store/plugin/store.go @@ -32,15 +32,6 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/errors" ) -// Error strings. -const ( - errGet = "cannot get secret" - errApply = "cannot apply secret" - errDelete = "cannot delete secret" - - errFmtCannotDial = "cannot dial to the endpoint: %s" -) - // SecretStore is an External Secret Store. type SecretStore struct { client essproto.ExternalSecretStorePluginServiceClient @@ -55,7 +46,7 @@ func NewSecretStore(_ context.Context, kube client.Client, tcfg *tls.Config, cfg creds := credentials.NewTLS(tcfg) conn, err := grpc.Dial(cfg.Plugin.Endpoint, grpc.WithTransportCredentials(creds)) if err != nil { - return nil, errors.Wrapf(err, errFmtCannotDial, cfg.Plugin.Endpoint) + return nil, errors.Wrapf(err, "cannot dial to the endpoint: %s", cfg.Plugin.Endpoint) } return &SecretStore{ @@ -70,7 +61,7 @@ func NewSecretStore(_ context.Context, kube client.Client, tcfg *tls.Config, cfg func (ss *SecretStore) ReadKeyValues(ctx context.Context, n store.ScopedName, s *store.Secret) error { resp, err := ss.client.GetSecret(ctx, &essproto.GetSecretRequest{Secret: &essproto.Secret{ScopedName: ss.getScopedName(n)}, Config: ss.getConfigReference()}) if err != nil { - return errors.Wrap(err, errGet) + return errors.Wrap(err, "cannot get secret") } s.ScopedName = n @@ -107,7 +98,7 @@ func (ss *SecretStore) WriteKeyValues(ctx context.Context, s *store.Secret, _ .. resp, err := ss.client.ApplySecret(ctx, &essproto.ApplySecretRequest{Secret: sec, Config: ss.getConfigReference()}) if err != nil { - return false, errors.Wrap(err, errApply) + return false, errors.Wrap(err, "cannot apply secret") } return resp.Changed, nil @@ -117,7 +108,7 @@ func (ss *SecretStore) WriteKeyValues(ctx context.Context, s *store.Secret, _ .. func (ss *SecretStore) DeleteKeyValues(ctx context.Context, s *store.Secret, _ ...store.DeleteOption) error { _, err := ss.client.DeleteKeys(ctx, &essproto.DeleteKeysRequest{Secret: &essproto.Secret{ScopedName: ss.getScopedName(s.ScopedName)}, Config: ss.getConfigReference()}) - return errors.Wrap(err, errDelete) + return errors.Wrap(err, "cannot delete secret") } func (ss *SecretStore) getConfigReference() *essproto.ConfigReference { diff --git a/pkg/connection/store/plugin/store_test.go b/pkg/connection/store/plugin/store_test.go index 5219fd5c8..b693392c5 100644 --- a/pkg/connection/store/plugin/store_test.go +++ b/pkg/connection/store/plugin/store_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "google.golang.org/grpc" v1 "github.com/crossplane/crossplane-runtime/apis/common/v1" @@ -29,7 +30,6 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/connection/store" "github.com/crossplane/crossplane-runtime/pkg/connection/store/plugin/fake" "github.com/crossplane/crossplane-runtime/pkg/errors" - "github.com/crossplane/crossplane-runtime/pkg/test" ) const ( @@ -66,7 +66,7 @@ func TestReadKeyValues(t *testing.T) { }, want: want{ out: &store.Secret{}, - err: errors.Wrap(errBoom, errGet), + err: errBoom, }, }, "SuccessfulGet": { @@ -136,7 +136,7 @@ func TestReadKeyValues(t *testing.T) { err := ss.ReadKeyValues(ctx, tc.args.sn, s) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nss.ReadKeyValues(...): -want error, +got error:\n%s", tc.reason, diff) } @@ -171,7 +171,7 @@ func TestWriteKeyValues(t *testing.T) { }, want: want{ isChanged: false, - err: errors.Wrap(errBoom, errApply), + err: errBoom, }, }, "SuccessfulWrite": { @@ -208,7 +208,7 @@ func TestWriteKeyValues(t *testing.T) { isChanged, err := ss.WriteKeyValues(ctx, s) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nss.WriteKeyValues(...): -want error, +got error:\n%s", tc.reason, diff) } @@ -240,7 +240,7 @@ func TestDeleteKeyValues(t *testing.T) { }}, }, want: want{ - err: errors.Wrap(errBoom, errDelete), + err: errBoom, }, }, "SuccessfulDelete": { @@ -272,7 +272,7 @@ func TestDeleteKeyValues(t *testing.T) { err := ss.DeleteKeyValues(ctx, s) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nss.DeletKeyValues(...): -want error, +got error:\n%s", tc.reason, diff) } }) diff --git a/pkg/connection/stores.go b/pkg/connection/stores.go index 924d800f3..e351e52b0 100644 --- a/pkg/connection/stores.go +++ b/pkg/connection/stores.go @@ -28,10 +28,6 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/errors" ) -const ( - errFmtUnknownSecretStore = "unknown secret store type: %q" -) - // RuntimeStoreBuilder builds and returns a Store for any supported Store type // in a given config. // @@ -43,5 +39,5 @@ func RuntimeStoreBuilder(ctx context.Context, local client.Client, tcfg *tls.Con case v1.SecretStorePlugin: return plugin.NewSecretStore(ctx, local, tcfg, cfg) } - return nil, errors.Errorf(errFmtUnknownSecretStore, *cfg.Type) + return nil, errors.Errorf("unknown secret store type: %q", *cfg.Type) } diff --git a/pkg/controller/engine_test.go b/pkg/controller/engine_test.go index 1abca9f36..fdb54861e 100644 --- a/pkg/controller/engine_test.go +++ b/pkg/controller/engine_test.go @@ -22,6 +22,7 @@ import ( "time" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -32,7 +33,6 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/errors" "github.com/crossplane/crossplane-runtime/pkg/resource/fake" - "github.com/crossplane/crossplane-runtime/pkg/test" ) type MockCache struct { @@ -169,7 +169,7 @@ func TestEngine(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { err := tc.e.Start(tc.args.name, tc.args.o, tc.args.w...) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\ne.Start(...): -want error, +got error:\n%s", tc.reason, diff) } @@ -178,7 +178,7 @@ func TestEngine(t *testing.T) { time.Sleep(100 * time.Millisecond) tc.e.Stop(tc.args.name) - if diff := cmp.Diff(tc.want.crash, tc.e.Err(tc.args.name), test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.crash, tc.e.Err(tc.args.name), cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\ne.Err(...): -want error, +got error:\n%s", tc.reason, diff) } }) diff --git a/pkg/errors/errors_test.go b/pkg/errors/errors_test.go index 479a72470..90cb58f7b 100644 --- a/pkg/errors/errors_test.go +++ b/pkg/errors/errors_test.go @@ -20,8 +20,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - - "github.com/crossplane/crossplane-runtime/pkg/test" + "github.com/google/go-cmp/cmp/cmpopts" ) func TestWrap(t *testing.T) { @@ -52,7 +51,7 @@ func TestWrap(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got := Wrap(tc.args.err, tc.args.message) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("Wrap(...): -want, +got:\n%s", diff) } }) @@ -89,7 +88,7 @@ func TestWrapf(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got := Wrapf(tc.args.err, tc.args.message, tc.args.args...) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("Wrapf(...): -want, +got:\n%s", diff) } }) @@ -118,7 +117,7 @@ func TestCause(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got := Cause(tc.err) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("Cause(...): -want, +got:\n%s", diff) } }) diff --git a/pkg/fieldpath/fieldpath_test.go b/pkg/fieldpath/fieldpath_test.go index 3b76f139e..6a9a96254 100644 --- a/pkg/fieldpath/fieldpath_test.go +++ b/pkg/fieldpath/fieldpath_test.go @@ -22,9 +22,9 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "github.com/crossplane/crossplane-runtime/pkg/errors" - "github.com/crossplane/crossplane-runtime/pkg/test" ) func TestSegments(t *testing.T) { @@ -297,7 +297,7 @@ func TestParse(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got, err := Parse(tc.path) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\nParse(%s): %s: -want error, +got error:\n%s", tc.path, tc.reason, diff) } if diff := cmp.Diff(tc.want.s, got); diff != "" { diff --git a/pkg/fieldpath/merge_test.go b/pkg/fieldpath/merge_test.go index 5753a3989..040571155 100644 --- a/pkg/fieldpath/merge_test.go +++ b/pkg/fieldpath/merge_test.go @@ -23,10 +23,10 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "k8s.io/apimachinery/pkg/util/json" xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" - "github.com/crossplane/crossplane-runtime/pkg/test" ) func TestMergeValue(t *testing.T) { @@ -200,7 +200,7 @@ func TestMergeValue(t *testing.T) { object: tc.fields.object, } err := p.MergeValue(tc.args.path, tc.args.value, tc.args.mo) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\np.MergeValue(%s, %v): %s: -want error, +got error:\n%s", tc.args.path, tc.args.value, tc.reason, diff) } diff --git a/pkg/fieldpath/paved_test.go b/pkg/fieldpath/paved_test.go index db00c3050..81c0157b6 100644 --- a/pkg/fieldpath/paved_test.go +++ b/pkg/fieldpath/paved_test.go @@ -27,7 +27,6 @@ import ( "k8s.io/apimachinery/pkg/util/json" "github.com/crossplane/crossplane-runtime/pkg/errors" - "github.com/crossplane/crossplane-runtime/pkg/test" ) func TestIsNotFound(t *testing.T) { @@ -170,7 +169,7 @@ func TestGetValue(t *testing.T) { p := Pave(in) got, err := p.GetValue(tc.path) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\np.GetValue(%s): %s: -want error, +got error:\n%s", tc.path, tc.reason, diff) } if diff := cmp.Diff(tc.want.value, got); diff != "" { @@ -246,7 +245,7 @@ func TestGetValueInto(t *testing.T) { p := Pave(in) err := p.GetValueInto(tc.args.path, tc.args.out) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\np.GetValueInto(%s): %s: -want error, +got error:\n%s", tc.args.path, tc.reason, diff) } if diff := cmp.Diff(tc.want.out, tc.args.out); diff != "" { @@ -299,7 +298,7 @@ func TestGetString(t *testing.T) { p := Pave(in) got, err := p.GetString(tc.path) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\np.GetString(%s): %s: -want error, +got error:\n%s", tc.path, tc.reason, diff) } if diff := cmp.Diff(tc.want.value, got); diff != "" { @@ -360,7 +359,7 @@ func TestGetStringArray(t *testing.T) { p := Pave(in) got, err := p.GetStringArray(tc.path) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\np.GetStringArray(%s): %s: -want error, +got error:\n%s", tc.path, tc.reason, diff) } if diff := cmp.Diff(tc.want.value, got); diff != "" { @@ -421,7 +420,7 @@ func TestGetStringObject(t *testing.T) { p := Pave(in) got, err := p.GetStringObject(tc.path) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\np.GetStringObject(%s): %s: -want error, +got error:\n%s", tc.path, tc.reason, diff) } if diff := cmp.Diff(tc.want.value, got); diff != "" { @@ -474,7 +473,7 @@ func TestGetBool(t *testing.T) { p := Pave(in) got, err := p.GetBool(tc.path) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\np.GetBool(%s): %s: -want error, +got error:\n%s", tc.path, tc.reason, diff) } if diff := cmp.Diff(tc.want.value, got); diff != "" { @@ -527,7 +526,7 @@ func TestGetInteger(t *testing.T) { p := Pave(in) got, err := p.GetInteger(tc.path) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\np.GetNumber(%s): %s: -want error, +got error:\n%s", tc.path, tc.reason, diff) } if diff := cmp.Diff(tc.want.value, got); diff != "" { @@ -801,7 +800,7 @@ func TestSetValue(t *testing.T) { p := Pave(in, tc.args.opts...) err := p.SetValue(tc.args.path, tc.args.value) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\np.SetValue(%s, %v): %s: -want error, +got error:\n%s", tc.args.path, tc.args.value, tc.reason, diff) } if diff := cmp.Diff(tc.want.object, p.object); diff != "" { @@ -958,7 +957,7 @@ func TestExpandWildcards(t *testing.T) { p := Pave(in) got, err := p.ExpandWildcards(tc.path) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\np.ExpandWildcards(%s): %s: -want error, +got error:\n%s", tc.path, tc.reason, diff) } if diff := cmp.Diff(tc.want.expanded, got, cmpopts.SortSlices(func(x, y string) bool { @@ -1246,7 +1245,7 @@ func TestDeleteField(t *testing.T) { p := Pave(in) err := p.DeleteField(tc.args.path) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Fatalf("\np.DeleteField(%s): %s: -want error, +got error:\n%s", tc.args.path, tc.reason, diff) } if diff := cmp.Diff(tc.want.object, p.object); diff != "" { diff --git a/pkg/meta/meta_test.go b/pkg/meta/meta_test.go index 4936292e7..69e9b67a4 100644 --- a/pkg/meta/meta_test.go +++ b/pkg/meta/meta_test.go @@ -21,6 +21,7 @@ import ( "time" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" @@ -28,7 +29,6 @@ import ( xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" "github.com/crossplane/crossplane-runtime/pkg/errors" - "github.com/crossplane/crossplane-runtime/pkg/test" ) const ( @@ -426,7 +426,7 @@ func TestAddControllerReference(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { err := AddControllerReference(tc.args.o, tc.args.r) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("AddControllerReference(...): -want error, +got error:\n%s", diff) } diff --git a/pkg/parser/linter_test.go b/pkg/parser/linter_test.go index 10e640490..403d0fee7 100644 --- a/pkg/parser/linter_test.go +++ b/pkg/parser/linter_test.go @@ -20,10 +20,10 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "k8s.io/apimachinery/pkg/runtime" "github.com/crossplane/crossplane-runtime/pkg/errors" - "github.com/crossplane/crossplane-runtime/pkg/test" ) var _ Linter = &PackageLinter{} @@ -120,7 +120,7 @@ func TestLinter(t *testing.T) { t.Run(name, func(t *testing.T) { err := tc.args.linter.Lint(tc.args.pkg) - if diff := cmp.Diff(tc.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nl.Lint(...): -want error, +got error:\n%s", tc.reason, diff) } }) @@ -176,7 +176,7 @@ func TestOr(t *testing.T) { t.Run(name, func(t *testing.T) { err := Or(tc.args.one, tc.args.two)(crd) - if diff := cmp.Diff(tc.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nOr(...): -want error, +got error:\n%s", tc.reason, diff) } }) diff --git a/pkg/ratelimiter/reconciler_test.go b/pkg/ratelimiter/reconciler_test.go index c8cdf5963..7e5ea8cad 100644 --- a/pkg/ratelimiter/reconciler_test.go +++ b/pkg/ratelimiter/reconciler_test.go @@ -22,11 +22,10 @@ import ( "time" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/ratelimiter" "sigs.k8s.io/controller-runtime/pkg/reconcile" - - "github.com/crossplane/crossplane-runtime/pkg/test" ) var _ ratelimiter.RateLimiter = &predictableRateLimiter{} @@ -100,7 +99,7 @@ func TestReconcile(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got, err := tc.r.Reconcile(tc.args.ctx, tc.args.req) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("%s\nr.Reconcile(...): -want, +got error:\n%s", tc.reason, diff) } if diff := cmp.Diff(tc.want.res, got); diff != "" { diff --git a/pkg/reconciler/managed/api_test.go b/pkg/reconciler/managed/api_test.go index 47b491b14..459fda0df 100644 --- a/pkg/reconciler/managed/api_test.go +++ b/pkg/reconciler/managed/api_test.go @@ -21,6 +21,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -107,7 +108,7 @@ func TestNameAsExternalName(t *testing.T) { t.Run(name, func(t *testing.T) { api := NewNameAsExternalName(tc.client) err := api.Initialize(tc.args.ctx, tc.args.mg) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("api.Initialize(...): -want error, +got error:\n%s", diff) } if diff := cmp.Diff(tc.want.mg, tc.args.mg, test.EquateConditions()); diff != "" { @@ -224,7 +225,7 @@ func TestAPISecretPublisher(t *testing.T) { t.Run(name, func(t *testing.T) { a := &APISecretPublisher{tc.fields.secret, tc.fields.typer} got, gotErr := a.PublishConnection(tc.args.ctx, tc.args.mg, tc.args.c) - if diff := cmp.Diff(tc.want.err, gotErr, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, gotErr, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nPublish(...): -wantErr, +gotErr:\n%s", tc.reason, diff) } if diff := cmp.Diff(tc.want.published, got); diff != "" { @@ -348,7 +349,7 @@ func TestResolveReferences(t *testing.T) { t.Run(name, func(t *testing.T) { r := NewAPISimpleReferenceResolver(tc.c) got := r.ResolveReferences(tc.args.ctx, tc.args.mg) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nr.ResolveReferences(...): -want, +got:\n%s", tc.reason, diff) } }) @@ -408,7 +409,7 @@ func TestRetryingCriticalAnnotationUpdater(t *testing.T) { t.Run(name, func(t *testing.T) { u := NewRetryingCriticalAnnotationUpdater(tc.c) got := u.UpdateCriticalAnnotations(tc.args.ctx, tc.args.o) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nu.UpdateCriticalAnnotations(...): -want, +got:\n%s", tc.reason, diff) } }) diff --git a/pkg/reconciler/managed/publisher_test.go b/pkg/reconciler/managed/publisher_test.go index 928b8fde2..17419f8e5 100644 --- a/pkg/reconciler/managed/publisher_test.go +++ b/pkg/reconciler/managed/publisher_test.go @@ -21,12 +21,12 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" "github.com/crossplane/crossplane-runtime/pkg/errors" "github.com/crossplane/crossplane-runtime/pkg/resource" "github.com/crossplane/crossplane-runtime/pkg/resource/fake" - "github.com/crossplane/crossplane-runtime/pkg/test" ) var ( @@ -106,7 +106,7 @@ func TestPublisherChain(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got, gotErr := tc.p.PublishConnection(tc.args.ctx, tc.args.mg, tc.args.c) - if diff := cmp.Diff(tc.want.err, gotErr, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, gotErr, cmpopts.EquateErrors()); diff != "" { t.Errorf("Publish(...): -want, +got:\n%s", diff) } if diff := cmp.Diff(tc.want.published, got); diff != "" { @@ -152,7 +152,7 @@ func TestDisabledSecretStorePublish(t *testing.T) { t.Run(name, func(t *testing.T) { ss := &DisabledSecretStoreManager{} got, gotErr := ss.PublishConnection(context.Background(), tc.args.mg, nil) - if diff := cmp.Diff(tc.want.err, gotErr, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, gotErr, cmpopts.EquateErrors()); diff != "" { t.Errorf("Publish(...): -want, +got:\n%s", diff) } if diff := cmp.Diff(tc.want.published, got); diff != "" { @@ -197,7 +197,7 @@ func TestDisabledSecretStoreUnpublish(t *testing.T) { t.Run(name, func(t *testing.T) { ss := &DisabledSecretStoreManager{} gotErr := ss.UnpublishConnection(context.Background(), tc.args.mg, nil) - if diff := cmp.Diff(tc.want.err, gotErr, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, gotErr, cmpopts.EquateErrors()); diff != "" { t.Errorf("Publish(...): -want, +got:\n%s", diff) } }) diff --git a/pkg/reconciler/managed/reconciler_test.go b/pkg/reconciler/managed/reconciler_test.go index 9e4930a71..761219a7a 100644 --- a/pkg/reconciler/managed/reconciler_test.go +++ b/pkg/reconciler/managed/reconciler_test.go @@ -1686,7 +1686,7 @@ func TestReconciler(t *testing.T) { r := NewReconciler(tc.args.m, tc.args.mg, tc.args.o...) got, err := r.Reconcile(context.Background(), reconcile.Request{}) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nReason: %s\nr.Reconcile(...): -want error, +got error:\n%s", tc.reason, diff) } @@ -1796,7 +1796,7 @@ func TestManagementPoliciesResolverValidate(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { r := NewManagementPoliciesResolver(tc.args.enabled, tc.args.policy, xpv1.DeletionDelete) - if diff := cmp.Diff(tc.want, r.Validate(), test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, r.Validate(), cmpopts.EquateErrors()); diff != "" { t.Errorf("\nReason: %s\nIsNonDefault(...): -want, +got:\n%s", tc.reason, diff) } }) diff --git a/pkg/reconciler/providerconfig/reconciler_test.go b/pkg/reconciler/providerconfig/reconciler_test.go index ef4332ef7..f04766c7c 100644 --- a/pkg/reconciler/providerconfig/reconciler_test.go +++ b/pkg/reconciler/providerconfig/reconciler_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -322,7 +323,7 @@ func TestReconciler(t *testing.T) { r := NewReconciler(tc.args.m, tc.args.of) got, err := r.Reconcile(context.Background(), reconcile.Request{}) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nr.Reconcile(...): -want error, +got error:\n%s", tc.reason, diff) } diff --git a/pkg/reference/reference_test.go b/pkg/reference/reference_test.go index 99f1a1733..3b6c2335a 100644 --- a/pkg/reference/reference_test.go +++ b/pkg/reference/reference_test.go @@ -431,7 +431,7 @@ func TestResolve(t *testing.T) { t.Run(name, func(t *testing.T) { r := NewAPIResolver(tc.c, tc.from) got, err := r.Resolve(tc.args.ctx, tc.args.req) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nControllersMustMatch(...): -want error, +got error:\n%s", tc.reason, diff) } if diff := cmp.Diff(tc.want.rsp, got); diff != "" { @@ -748,7 +748,7 @@ func TestResolveMultiple(t *testing.T) { t.Run(name, func(t *testing.T) { r := NewAPIResolver(tc.c, tc.from) got, err := r.ResolveMultiple(tc.args.ctx, tc.args.req) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nControllersMustMatch(...): -want error, +got error:\n%s", tc.reason, diff) } if diff := cmp.Diff(tc.want.rsp, got, cmpopts.EquateEmpty()); diff != "" { diff --git a/pkg/resource/api_test.go b/pkg/resource/api_test.go index 731cee31e..f56c50e59 100644 --- a/pkg/resource/api_test.go +++ b/pkg/resource/api_test.go @@ -21,6 +21,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -143,7 +144,7 @@ func TestAPIPatchingApplicator(t *testing.T) { t.Run(name, func(t *testing.T) { a := NewAPIPatchingApplicator(tc.c) err := a.Apply(tc.args.ctx, tc.args.o, tc.args.ao...) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nApply(...): -want error, +got error\n%s\n", tc.reason, diff) } if diff := cmp.Diff(tc.want.o, tc.args.o); diff != "" { @@ -271,7 +272,7 @@ func TestAPIUpdatingApplicator(t *testing.T) { t.Run(name, func(t *testing.T) { a := NewAPIUpdatingApplicator(tc.c) err := a.Apply(tc.args.ctx, tc.args.o, tc.args.ao...) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nApply(...): -want error, +got error\n%s\n", tc.reason, diff) } if diff := cmp.Diff(tc.want.o, tc.args.o); diff != "" { @@ -329,7 +330,7 @@ func TestManagedRemoveFinalizer(t *testing.T) { t.Run(name, func(t *testing.T) { api := NewAPIFinalizer(tc.client, finalizer) err := api.RemoveFinalizer(tc.args.ctx, tc.args.obj) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("api.RemoveFinalizer(...): -want error, +got error:\n%s", diff) } if diff := cmp.Diff(tc.want.obj, tc.args.obj, test.EquateConditions()); diff != "" { @@ -387,7 +388,7 @@ func TestAPIFinalizerAdder(t *testing.T) { t.Run(name, func(t *testing.T) { api := NewAPIFinalizer(tc.client, finalizer) err := api.AddFinalizer(tc.args.ctx, tc.args.obj) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("api.Initialize(...): -want error, +got error:\n%s", diff) } if diff := cmp.Diff(tc.want.obj, tc.args.obj, test.EquateConditions()); diff != "" { diff --git a/pkg/resource/providerconfig_test.go b/pkg/resource/providerconfig_test.go index eb973bb6f..da29c5e92 100644 --- a/pkg/resource/providerconfig_test.go +++ b/pkg/resource/providerconfig_test.go @@ -21,6 +21,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "github.com/spf13/afero" corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -76,7 +77,7 @@ func TestExtractEnv(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got, err := ExtractEnv(context.TODO(), tc.args.e, tc.args.creds) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\npc.ExtractEnv(...): -want error, +got error:\n%s\n", tc.reason, diff) } if diff := cmp.Diff(tc.want.b, got); diff != "" { @@ -135,7 +136,7 @@ func TestExtractFs(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got, err := ExtractFs(context.TODO(), tc.args.fs, tc.args.creds) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\npc.ExtractFs(...): -want error, +got error:\n%s\n", tc.reason, diff) } if diff := cmp.Diff(tc.want.b, got); diff != "" { @@ -223,7 +224,7 @@ func TestExtractSecret(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got, err := ExtractSecret(context.TODO(), tc.args.client, tc.args.creds) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\npc.ExtractSecret(...): -want error, +got error:\n%s\n", tc.reason, diff) } if diff := cmp.Diff(tc.want.b, got); diff != "" { @@ -319,7 +320,7 @@ func TestTrack(t *testing.T) { t.Run(name, func(t *testing.T) { ut := &ProviderConfigUsageTracker{c: tc.fields.c, of: tc.fields.of} got := ut.Track(tc.args.ctx, tc.args.mg) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nut.Track(...): -want error, +got error:\n%s\n", tc.reason, diff) } }) diff --git a/pkg/resource/resource_test.go b/pkg/resource/resource_test.go index 8a506dea8..c116f5162 100644 --- a/pkg/resource/resource_test.go +++ b/pkg/resource/resource_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" corev1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -35,7 +36,6 @@ import ( xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" "github.com/crossplane/crossplane-runtime/pkg/errors" "github.com/crossplane/crossplane-runtime/pkg/resource/fake" - "github.com/crossplane/crossplane-runtime/pkg/test" ) const ( @@ -240,7 +240,7 @@ func TestGetKind(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got, err := GetKind(tc.args.obj, tc.args.ot) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("GetKind(...): -want error, +got error:\n%s", diff) } if diff := cmp.Diff(tc.want.kind, got); diff != "" { @@ -307,7 +307,7 @@ func TestIgnore(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got := Ignore(tc.args.is, tc.args.err) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("Ignore(...): -want error, +got error:\n%s", diff) } }) @@ -354,7 +354,7 @@ func TestIgnoreAny(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { got := IgnoreAny(tc.args.err, tc.args.is...) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("Ignore(...): -want error, +got error:\n%s", diff) } }) @@ -488,7 +488,7 @@ func TestMustBeControllableBy(t *testing.T) { ao := MustBeControllableBy(tc.u) err := ao(tc.args.ctx, tc.args.current, tc.args.desired) - if diff := cmp.Diff(tc.want, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nMustBeControllableBy(...)(...): -want error, +got error\n%s\n", tc.reason, diff) } }) @@ -560,7 +560,7 @@ func TestConnectionSecretMustBeControllableBy(t *testing.T) { ao := ConnectionSecretMustBeControllableBy(tc.u) err := ao(tc.args.ctx, tc.args.current, tc.args.desired) - if diff := cmp.Diff(tc.want, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nConnectionSecretMustBeControllableBy(...)(...): -want error, +got error\n%s\n", tc.reason, diff) } }) @@ -602,7 +602,7 @@ func TestAllowUpdateIf(t *testing.T) { ao := AllowUpdateIf(tc.fn) err := ao(tc.args.ctx, tc.args.current, tc.args.desired) - if diff := cmp.Diff(tc.want, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nAllowUpdateIf(...)(...): -want error, +got error\n%s\n", tc.reason, diff) } }) @@ -811,7 +811,7 @@ func TestApplicatorWithRetry_Apply(t *testing.T) { backoff: tc.fields.backoff, } - if diff := cmp.Diff(tc.wantErr, awr.Apply(tc.args.ctx, tc.args.c, tc.args.opts...), test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.wantErr, awr.Apply(tc.args.ctx, tc.args.c, tc.args.opts...), cmpopts.EquateErrors()); diff != "" { t.Fatalf("ApplicatorWithRetry.Apply(...): -want, +got:\n%s", diff) } diff --git a/pkg/resource/unstructured/client_test.go b/pkg/resource/unstructured/client_test.go index a68c30d32..a9254b703 100644 --- a/pkg/resource/unstructured/client_test.go +++ b/pkg/resource/unstructured/client_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/controller-runtime/pkg/client" @@ -108,7 +109,7 @@ func TestGet(t *testing.T) { t.Run(name, func(t *testing.T) { c := NewClient(tc.c) got := c.Get(tc.args.ctx, tc.args.key, tc.args.obj) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nc.Get(...): -want error, +got error:\n %s", diff) } }) @@ -151,7 +152,7 @@ func TestList(t *testing.T) { t.Run(name, func(t *testing.T) { c := NewClient(tc.c) got := c.List(tc.args.ctx, tc.args.obj) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nc.List(...): -want error, +got error:\n %s", diff) } }) @@ -192,7 +193,7 @@ func TestCreate(t *testing.T) { t.Run(name, func(t *testing.T) { c := NewClient(tc.c) got := c.Create(tc.args.ctx, tc.args.obj) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nc.Create(...): -want error, +got error:\n %s", diff) } }) @@ -233,7 +234,7 @@ func TestDelete(t *testing.T) { t.Run(name, func(t *testing.T) { c := NewClient(tc.c) got := c.Delete(tc.args.ctx, tc.args.obj) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nc.Delete(...): -want error, +got error:\n %s", diff) } }) @@ -274,7 +275,7 @@ func TestUpdate(t *testing.T) { t.Run(name, func(t *testing.T) { c := NewClient(tc.c) got := c.Update(tc.args.ctx, tc.args.obj) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nc.Update(...): -want error, +got error:\n %s", diff) } }) @@ -316,7 +317,7 @@ func TestPatch(t *testing.T) { t.Run(name, func(t *testing.T) { c := NewClient(tc.c) got := c.Patch(tc.args.ctx, tc.args.obj, tc.args.patch) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nc.Patch(...): -want error, +got error:\n %s", diff) } }) @@ -357,7 +358,7 @@ func TestDeleteAllOf(t *testing.T) { t.Run(name, func(t *testing.T) { c := NewClient(tc.c) got := c.DeleteAllOf(tc.args.ctx, tc.args.obj) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nc.DeleteAllOf(...): -want error, +got error:\n %s", diff) } }) @@ -399,7 +400,7 @@ func TestStatusCreate(t *testing.T) { t.Run(name, func(t *testing.T) { c := NewClient(tc.c) got := c.Status().Create(tc.args.ctx, tc.args.obj, tc.args.sub) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nc.Status().Create(...): -want error, +got error:\n %s", diff) } }) @@ -440,7 +441,7 @@ func TestStatusUpdate(t *testing.T) { t.Run(name, func(t *testing.T) { c := NewClient(tc.c) got := c.Status().Update(tc.args.ctx, tc.args.obj) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nc.Status().Update(...): -want error, +got error:\n %s", diff) } }) @@ -482,7 +483,7 @@ func TestStatusPatch(t *testing.T) { t.Run(name, func(t *testing.T) { c := NewClient(tc.c) got := c.Status().Patch(tc.args.ctx, tc.args.obj, tc.args.patch) - if diff := cmp.Diff(tc.want, got, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want, got, cmpopts.EquateErrors()); diff != "" { t.Errorf("\nc.StatusPatch(...): -want error, +got error:\n %s", diff) } }) diff --git a/pkg/webhook/mutator_test.go b/pkg/webhook/mutator_test.go index 8ad7e4c03..da13b4526 100644 --- a/pkg/webhook/mutator_test.go +++ b/pkg/webhook/mutator_test.go @@ -21,10 +21,9 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/webhook" - - "github.com/crossplane/crossplane-runtime/pkg/test" ) // Mutator has to satisfy CustomDefaulter interface so that it can be used by @@ -72,7 +71,7 @@ func TestDefault(t *testing.T) { t.Run(name, func(t *testing.T) { v := NewMutator(WithMutationFns(tc.fns...)) err := v.Default(context.TODO(), tc.args.obj) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nDefault(...): -want, +got\n%s\n", tc.reason, diff) } }) diff --git a/pkg/webhook/validator_test.go b/pkg/webhook/validator_test.go index 8d2455526..7677a802e 100644 --- a/pkg/webhook/validator_test.go +++ b/pkg/webhook/validator_test.go @@ -27,7 +27,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook/admission" "github.com/crossplane/crossplane-runtime/pkg/errors" - "github.com/crossplane/crossplane-runtime/pkg/test" ) // Validator has to satisfy CustomValidator interface so that it can be used by @@ -106,7 +105,7 @@ func TestValidateCreate(t *testing.T) { t.Run(name, func(t *testing.T) { v := NewValidator(WithValidateCreationFns(tc.fns...)) warn, err := v.ValidateCreate(context.TODO(), tc.args.obj) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nValidateCreate(...): -want error, +got error\n%s\n", tc.reason, diff) } if diff := cmp.Diff(tc.want.warnings, warn, cmpopts.EquateEmpty()); diff != "" { @@ -186,7 +185,7 @@ func TestValidateUpdate(t *testing.T) { t.Run(name, func(t *testing.T) { v := NewValidator(WithValidateUpdateFns(tc.fns...)) warn, err := v.ValidateUpdate(context.TODO(), tc.args.oldObj, tc.args.newObj) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nValidateUpdate(...): -want error, +got error\n%s\n", tc.reason, diff) } if diff := cmp.Diff(tc.want.warnings, warn, cmpopts.EquateEmpty()); diff != "" { @@ -265,7 +264,7 @@ func TestValidateDelete(t *testing.T) { t.Run(name, func(t *testing.T) { v := NewValidator(WithValidateDeletionFns(tc.fns...)) warn, err := v.ValidateDelete(context.TODO(), tc.args.obj) - if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { t.Errorf("\n%s\nValidateDelete(...): -want error, +got error\n%s\n", tc.reason, diff) } if diff := cmp.Diff(tc.want.warnings, warn, cmpopts.EquateEmpty()); diff != "" {