derision-test / go-mockgen

MIT License
57 stars 7 forks source link

Way to rename constructor functions? #25

Closed kasvtv closed 2 years ago

kasvtv commented 2 years ago

First off, this module is absolutely sublime. Wonderfully convenient for developers to use. Absolutely stellar job creating the developer-facing API! This should be the number one mocking module for Gophers!

The only shortcoming I experience is as follows:

My common workflow with this module, is to generate a bunch of mocks from my interfaces, and then, for some, but not all of the mocks, create a custom wrapper function that first calls the generated constructor function, then assigns a bunch of default returns or default hooks, and return the result. This allows for a super simple way of getting a mock with sensible defaults inside of a unit test (and optionally further change some of the hooks to simulate the scenario that you want to test).

I'd like to keep these custom constructors in the same package as the mock objects, and then apply the NewMock**** function naming convention for my custom constructors (essentially replacing the generated constructor), to signify to other developers that this is the standard mock to use.

What I tried so far:

Any suggestions on how to do this better?

Thanks again for the amazing module.

efritz commented 2 years ago

Would an additional --ctor-prefix flag that allows you to insert some other name into just the constructor and not all types work for this use-case?

kasvtv commented 2 years ago

Would an additional --ctor-prefix flag that allows you to insert some other name into just the constructor and not all types work for this use-case?

Yes, certainly!!