You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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.
Copy file name to clipboardExpand all lines: docs/configuration.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,6 +57,7 @@ Parameter Descriptions
57
57
|`exclude-subpkg-regex`| :fontawesome-solid-x: |`#!yaml []`| A list of regular expressions that denote which subpackages should be excluded when `#!yaml recursive: true`|
58
58
|`exclude-regex`| :fontawesome-solid-x: |`#!yaml ""`| When set along with `include-regex`, then interfaces which match `include-regex` but also match `exclude-regex` will not be generated. If `all` is set, or if `include-regex` is not set, then `exclude-regex` has no effect. |
59
59
|`filename`| :fontawesome-solid-check: |`#!yaml "mock_{{.InterfaceName}}.go"`| The name of the file the mock will reside in. |
60
+
|`force-file-write`| :fontawesome-solid-x: |`#!yaml false`| When set to `#!yaml force-file-write: true`, mockery will forcibly overwrite any existing files. |
60
61
|`formatter`| :fontawesome-solid-x: |`#!yaml "goimports"`| The formatter to use on the rendered template. Choices are: `gofmt`, `goimports`, `noop`. |
61
62
|`include-regex`| :fontawesome-solid-x: |`#!yaml ""`| When set, only interface names that match the expression will be generated. This setting is ignored if `all: True` is specified in the configuration. To further refine the interfaces generated, use `exclude-regex`. |
62
63
|`log-level`| :fontawesome-solid-x: |`#!yaml "info"`| Set the level of the logger |
@@ -65,11 +66,25 @@ Parameter Descriptions
65
66
|[`packages`](features.md#packages-configuration)| :fontawesome-solid-x: |`#!yaml null`| A dictionary containing configuration describing the packages and interfaces to generate mocks for. |
66
67
|`pkgname`| :fontawesome-solid-check: | `#!yaml "{{.SrcPackageName}}" | The `#!go package name` given to the generated mock files. |
67
68
|[`recursive`](features.md#recursive-package-discovery)| :fontawesome-solid-x: |`#!yaml false`| When set to `true` on a particular package, mockery will recursively search for all sub-packages and inject those packages into the config map. |
69
+
|[`replace-type`](replace-type.md)| :fontawesome-solid-x: |`#!yaml {}`| Use this parameter to specify type replacements. |
68
70
|`tags`| :fontawesome-solid-x: |`#!yaml ""`| A space-separated list of additional build tags to load packages. |
69
71
|`template`| :fontawesome-solid-x: |`#!yaml ""`| The template to use. The choices are `moq`, `mockery`, or a file path provided by `file://path/to/file.txt`. |
70
72
|`template-data`| :fontawesome-solid-x: |`#!yaml {}`| A `map[string]any` that provides arbitrary options to the template. Each template will have a different set of accepted keys. Refer to each template's documentation for more details. |
71
73
72
74
75
+
Config Templates
76
+
----------------
77
+
78
+
Parameters marked as being templated have access to a number of template variables and functions.
79
+
80
+
### Variables
81
+
82
+
The variables provided are specified in the [`ConfigData`](https://pkg.go.dev/github.com/vektra/mockery/v3/template#ConfigData) struct.
83
+
84
+
### Functions
85
+
86
+
All of the functions defined in [`StringManipulationFuncs`](https://pkg.go.dev/github.com/vektra/mockery/v3/template#pkg-variables) are available to templated parameters.
This parameter is useful if you need to need to work around packages that use internal types. Take for example the situation found [here](https://github.com/vektra/mockery/issues/864#issuecomment-2567788637), noted by [RangelReale](https://github.com/RangelReale).
0 commit comments