-
Notifications
You must be signed in to change notification settings - Fork 94
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
Support external fake templates #98
Comments
A different approach could be to introduce the notion of a header. By default it should be This would fit my current use-case where I want to use counterfeiter in kubernetes repos and have to prepend generated files with this header. I could then potentially use counterfeiter with //go:generate counterfeiter -header-file $KUBE_ROOT/hack/boilerplate/boilerplate.generatego.txt . TheInterfaceToFake Pros:
Cons / Risks:
|
Do you REALLY need this feature ? Additional handles/toggles make a package harder to understand, lead to documentation bloat. What would be real world use-cases for such functionality ? |
Well, I don't REALLY need it -- I can always slap some sh around counterfeiter which handles that. However I believe that this usecase (having a licence header or such on all files) is a common enough scenario that counterfeiter authors could think about directly supporting. I can totally see the benefits of counterfeiter providing such a feature (see the real life k8s usecase above -- I'd love to use that without needing a wrapper around counterfeiter), but I can also understand if you all think that's not counterfeiter's responsibility and can see the added complexity you'd need to support. |
@hoegaarden, about licence header for generated code ... I see your point, but I personaly think (feel free to persuade me otherwise :) generated code shouldn't be checked into |
@LasTshaMAN I would make a somewhat educated guess that the vast majority of In general I do think we should find a way to achieve the outcome (the ability to set a custom header) that @hoegaarden (btw, such a great beer 🍺) is looking for. |
Why does this happen ? Do you think encouraging it (by adding features like this one) is a good idea ? |
I do prefer committing generated code for the most part, because it allows users to clone the repo and just run the thing (where in case of counterfeiter "the thing" are the tests, but you could also have generated production code). They don't need to know how to run the code generator or even have the code generator installed. When it comes to drift between the fake and the thing to be faked I feel counterfeiter protects that good enough by having the compile time assertion which checks if the fake actually implements the thing it is supposed to stand in for. I think counterfeiter does not have to impose one or the other way (you must or you must not commit the generated fake) and adding the feature to allow changing/adding a header does not really encourage one or the other from my point of view. Those are just my 0.02€ and still it is up to the counterfeiter maintainers to state if they'd support something like that or rather not. When it comes to the implementation I would love to spend some cycles on that ... but of course only if there is a chance that the PR will actually be accepted. |
Allow a user of
counterfeiter
to supply a path to their own fake template (based ontext/template
syntax) for use when generating a fake.This will allow users to:
Risks associated with this are:
The text was updated successfully, but these errors were encountered: