Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark test.EquateErrors as deprecated #529

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

negz
Copy link
Member

@negz negz commented Aug 24, 2023

Description of your changes

We can't remove this (it would be a breaking API change) but I want to discourage and redirect folks.

See crossplane/crossplane#4514 for context and more discussion. I've also updated this repo to follow the new pattern proposed in that issue, so it acts as an example of how tests might look if we choose to adopt it.

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

See crossplane/crossplane#4514 for context.

We can't remove this (it would be a breaking API change) but I want to
discourage and redirect folks.

Signed-off-by: Nic Cope <nicc@rk0n.org>
@negz negz requested review from a team as code owners August 24, 2023 18:04
@negz negz requested review from phisco and MisterMX August 24, 2023 18:04
@negz negz marked this pull request as draft August 24, 2023 18:05
@negz
Copy link
Member Author

negz commented Aug 24, 2023

Converting to draft because I forgot I had to update all the uses in this repo. 😆

To avoid doing a whole bunch of string comparison in unit tests, we also
switch to using cmpopts.EquateErrors.

Signed-off-by: Nic Cope <nicc@rk0n.org>
@negz negz marked this pull request as ready for review August 25, 2023 02:01
This way code in policies.go has its tests in policies_test.go, not
reconciler_test.go.

Signed-off-by: Nic Cope <nicc@rk0n.org>
@@ -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()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return errors.Errorf("existing secret is not woned by UID %q", string(so.GetUID()))
return errors.Errorf("existing secret is not owned by UID %q", string(so.GetUID()))

@@ -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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried implementing a custom EquateErrors based on errors.As, but unfortunately I couldn't make it work, so I guess we're stuck with cmptopts.AnyError.

@lsviben
Copy link
Contributor

lsviben commented Sep 3, 2024

This is approved, so if this PR is still relevant could we rebase and merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants