petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
252 stars 28 forks source link

Params is a keyword? #111

Open flyinprogrammer opened 3 years ago

flyinprogrammer commented 3 years ago

Context:

So I've stumbled upon needing to use this project while trying to resurrect the wildly out of date / broken slack client in Atlantis: https://github.com/runatlantis/atlantis/tree/master/server/events/webhooks

I'm not sure how much anyone cares about any of these rambles, but this community seems like they might care? So here we are.


So the first discovery I've found is trivial, defining an interface's method with a parameter named params makes our generator create broken code:

https://github.com/flyinprogrammer/pegomock_examples/blob/issues/params_keyword/slack.go#L8

https://github.com/flyinprogrammer/pegomock_examples/blob/issues/params_keyword/mocks/mock_slack_client.go#L32

The solution is to simply ignore the provided name params:

https://github.com/slack-go/slack/blob/master/conversation.go#L81

And do something like this:

https://github.com/flyinprogrammer/pegomock_examples/blob/workaround/params_keyword/slack.go#L8

https://github.com/flyinprogrammer/pegomock_examples/blob/workaround/params_keyword/mocks/mock_slack_client.go#L32

And we're off again.

sloth_smile

Not sure if we want to document this hiccup, or make our code generator smarter? Happy to contribute, just need some guidance.

petergtz commented 3 years ago

Hey @flyinprogrammer, thanks for reporting this and of course for the magnificent sloth there :-).

I think we should definitely make the code generator smarter here. Seems like the simplest would be to prefix or suffix the local variable names with _ or even __. These are against Go naming conventions (for normal code, but not generated one) and should make sure, we don't get this hiccup. I think that's not too difficult and would not require people to read through framework caveats.

I'd be very happy to merge that PR, if you decide to contribute.

Thank you, Peter