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

feat(v3): Warning for nonexistent mocks #911

Merged
merged 2 commits into from
Feb 4, 2025

Conversation

ravsii
Copy link
Contributor

@ravsii ravsii commented Feb 1, 2025

Description

Copy of #907 but for v3. Also, no log.Ctx() this time :D

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Version of Go used when building/testing:

  • 1.22
  • 1.23

How Has This Been Tested?

2025-02-01T19:46:07.124329000+03:00 WRN no such interface interface=InterfaceDoesntExist package-path=github.com/vektra/mockery/v3/internal version=v0.0.0-dev

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

On a side note, don’t you think that RootApp.Run is a little too big? Having 2 (or 3 now) huge loops with all the core logic feels like a bit too much. Just my two cents as an outside contributor.

I've also put my code in there, but looks like it could become a mess with more features

Copy link
Collaborator

@LandonTClipp LandonTClipp left a comment

Choose a reason for hiding this comment

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

Just a couple of tweaks and this should be good to go. Thanks for the PR!

Regarding your comment about the length of .Run(), I don't necessarily believe that functions need to be split up because of line counts. My philosophy is that you should break it up for any of the following reasons:

  1. To make unit testing easier.
  2. To factor out common bits of logic used in more than one place (or in other words, abstracting complex bits of logic out).
  3. To make it easier to understand what is happening.

There are little to no unit tests for this method because I'm relying much more heavily on e2e integration tests, so point 1 is moot. There is only one consumer of this logic, so point 2 is moot. And IMO the method is fairly easy to understand so point 3 is moot. I would prefer to have all the core business logic in one large-ish function if it makes it easier to follow the flow of the logic. Abstractions can sometimes run the risk of making it harder to know what's actually happening.

I understand this is just a preference, but from a practical perspective, I don't see a reason to break it up. But, I appreciate the perspective!

@@ -322,5 +356,16 @@ func (r *RootApp) Run() error {
}
}

// The loop above could exit early, so sometimes warnings won't be shown
// until other errors are fixed
for packageName := range missingMap {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for packageName := range missingMap {
for packagePath := range missingMap {

Technically, a "package name" is different from a "package path".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, fixed

log.Warn().
Str(logging.LogKeyInterface, iface).
Str(logging.LogKeyPackagePath, packageName).
Msg("no such interface")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Msg("no such interface")
Msg("interface not found in source")

Just to be a bit more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@ravsii ravsii requested a review from LandonTClipp February 4, 2025 16:15
@ravsii
Copy link
Contributor Author

ravsii commented Feb 4, 2025

Just pushed the requested changed, I hope it's good now.

Also thanks for such a detailed answer on Run(). Yeah, that totally makes sense

Copy link
Collaborator

@LandonTClipp LandonTClipp left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks again.

@LandonTClipp LandonTClipp merged commit 0c8aecf into vektra:v3 Feb 4, 2025
4 checks passed
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.

2 participants