maxbrunsfeld / counterfeiter

A tool for generating self-contained, type-safe test doubles in go
MIT License
931 stars 90 forks source link

Handle generic params and return types #258

Closed Ralph7C2 closed 6 months ago

Ralph7C2 commented 10 months ago

This only covers the case where the interface itself isn't generic but accepts or returns a generic with a concrete type arg.

Currently, the fake fails to import the package for the type arg. Now, while creating imports, we iterate over TypeArgs for named types and import the packages for them.

joefitzgerald commented 9 months ago

Thanks for this! I will take a detailed look in the next day, but at first glance it looks great 🙏

Ralph7C2 commented 8 months ago

Hey @joefitzgerald I'd like to resurrect this if I could, I just bumped into this problem again. https://goplay.tools/snippet/cRLlU7yek6Q is a summary

The problem could also be fixed if concrete types fulfilled interfaces with interfaces int heir methods (a mouthful, I know). But, that seems less likely and I think this patch would fix the issue for me(allowing to generate a fake for the specified generic in an interface)

joefitzgerald commented 8 months ago

Hey @Ralph7C2 sorry for the delay. Looking at this now.

zachgersh commented 7 months ago

Hey @joefitzgerald (hope you are doing well, long time no speak since our pivotal days). I hate to be that person but I also need this as well 👯

Hope you have some time to merge this, we using a work around for now!

joefitzgerald commented 6 months ago

@Ralph7C2, sorry for the lengthy delay in getting this merged (work got a little crazy). Thanks for the contribution!

Hi @zachgersh! It's great to hear from you!! You can always feel free to be that person 😄 ❤️.