-
Notifications
You must be signed in to change notification settings - Fork 422
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: Error message for nonexistent mocks #907
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good. I agree with not providing an option to turn the warning off. Good work!
func (p *Parser) Has(packageName, interfaceName string) bool { | ||
for _, entry := range p.files { | ||
if entry.pkg.PkgPath != packageName { | ||
continue | ||
} | ||
|
||
for _, ifaceName := range entry.interfaces { | ||
if ifaceName != interfaceName { | ||
continue | ||
} | ||
|
||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, obviously this is a polynomial runtime because of the linear iteration through all interfaces during each query, but it's probably fine? Simple is good 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is far from optimal, but since the parser stores entries as a slice, I don't think creating an additional map for that specific (and only) case is needed. (But could be done, feel free to ping me).
I hope nobody has tens of thousands of interfaces in a single project :D
PR vektra#907 used a feature of zerolog that did not exist in the version mockery depended on. It's still a mystery how CICD allowed this to happen, but I will release this fix before that investigation is complete.
PR #907 used a feature of zerolog that did not exist in the version mockery depended on. It's still a mystery how CICD allowed this to happen, but I will release this fix before that investigation is complete.
Description
Added a log message that warns user that he specified an interface that doesn't exist.
I did add an extra
Has
function for parser because main loop shouldn't have that kind of logic, given that parser already parsed the interfaces and has all the metainfo for them.I also decided to not add any flags because it seems like something that shouldn't be turned off as a separate feature, but it's still possible to set
log-level = error
and remove this for those who want it.Please let me know if I missed something! I will also do a PR for
v3
after this one will be accepted.Type of change
Version of Go used when building/testing:
How Has This Been Tested?
There's only one log message that was added, I'm know sure how/if we should test it. I can add tests for parser.Has, if needed, but the function itself is pretty simple.
Checklist