Closed kasvtv closed 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?
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!!
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:
--prefix=Base
as to be able to use theNewMock****
function naming convention for my custom constructorsBase
in the name, which is somewhat confusing. Ideally I would just rename the constructor function.NewMock****From
.NewMock****
convention and get the mock with the sensible defaults.Any suggestions on how to do this better?
Thanks again for the amazing module.