-
Notifications
You must be signed in to change notification settings - Fork 449
fix: constraint interfaces generation #1125
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
fix: constraint interfaces generation #1125
Conversation
internal/parse.go
Outdated
| // Example: | ||
| // type I interface { | ||
| // constraints.Float | ||
| // } | ||
| if sel, ok := item.Type.(*ast.SelectorExpr); ok { | ||
| if id, ok := sel.X.(*ast.Ident); ok && id.Name == "constraints" { | ||
| return true | ||
| } | ||
| } | ||
| } |
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 think this is fine but it's easily tricked. You can create an alias to a constraints.Float and this check would not catch it. You would need an additional check for alias types, then resolve the alias, then perform the same checks you added here.
That doesn't have to be included in this PR, but it's something to think about. You mention this in the description so I'm not telling you something new.
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.
Hi. Thanks for the tip. Thanks to this, i also found a way to check aliases for constraint interfaces
|
I haven't forgotten this, I will get to it soon! |
|
Merged, thanks again 🫡 |
Description
I added a check to the parser for whether the interface is a constraint. Mocks will not be generated using such interfaces.
Examples of interfaces that will be skipped:
Type of change
Version of Go used when building/testing:
How Has This Been Tested?
I wrote a test in fixtures with several constraint interfaces. If no mocks are generated for them, the test will be completed successfully.
Fixture path:
internal/fixtures/constraint_ifacesChecklist