-
Notifications
You must be signed in to change notification settings - Fork 424
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
v3: Remove all replace-type
functionality
#864
Comments
I found an edge case that may require that this parameter be kept:
package internal
type Options struct {
Dir string
}
package x
import "sample/x/internal"
type IType interface {
Calculate(options internal.Options)
} Generating a mock outside the It may be an edge case, but I found this problem on the The internal option type is also exported in the same root file, but mockery has no way to know this, so I'm using replace-type to fix this. Granted, this is not a very good design, but it is legal Go code, and may happen in other codebases. |
Hmm that's surprising to me that it's valid Go. We should probably create a fixture for it and add it to the tests. I'll look into adding it back. |
I can't think of a way around this, it's frustrating that someone would design an API like that! Alas, I will have to add it back. |
I have a working PR. Porting to v3 wasn't straightforward due to the requirements that the templates receive real type information, so we basically have to dynamically parse the referenced type. Had to change the schema of the parameter to make this easier/cleaner. Just need to add some tests and we'll be good. Only thing yet to be done is the support for replacing generic type parameters. |
* Add back `replace-types` Port the `replace-type` parameter into mockery v3. This changes the config schema used in the v2 replace-type parameter to be more grokable. This is also a practical matter: the somewhat complex parsing mechanism in v2 is replaced by simple struct attributes. The implementation here is quite different from v2. The templating system in v3 requires type information for all types, and thus we cannot do simple string replacements. We have to call `packages.Load` on the referenced type so we can get real type information. This means that `replace-type` will incur additional latency. This latency penalty, however, grants us additional correctness of implementation: the mock templates will have full type information, and if something about the `replace-type` parameter is wrong (either package path or type name don't exist), mockery will explicitly log this as an error. This does _not_ implement replacements of type constraints as done in v2: #750. This work still needs to be done. Per #864 * Additional documentation * Add docs and hint in log message on how to enable force-file-write.
Closing this as "won't do" since I re-implemented replace-type. |
This was needed to get around type aliases, but the Go AST fully supports aliases now so there is no need to have this anymore.
The text was updated successfully, but these errors were encountered: