mockery
mockery copied to clipboard
Configuration option `inpackage` is not functioning as expected
PLEASE READ
DO NOT submit tickets without first using the latest version of Golang, clearing your local golang package cache, and re-building mockery using the latest Golang version and the latest version of mockery. Please provide evidence this has been done in your issue. Failure to provide this evidence will likely result in your issue being closed.
Description
inpackage
config option is not used when used under packages
Mockery Version
2.43.0
Golang Version
1.22.2
Installation Method
- [ ] Binary Distribution
- [ ] Docker
- [x] brew
- [ ] go install
- [ ] Other: [specify]
Steps to Reproduce
- Use the
package
configuration method - Create a go module, e.g.
github.com/emreler/foo
- Define an interface in a subpackage, e.g.
github.com/emreler/foo/bar
- Create a
.mockery.yaml
config file like provided below - Run mockery
Config:
packages:
github.com/emreler/foo/bar:
config:
all: true
with-expecter: true
inpackage: true
Expected Behavior
Mock file to be created under github.com/emreler/foo/bar
Actual Behavior
Mock file is created under github.com/emreler/mocks/github.com/emreler/foo/bar
The issue seems to be not there when using the old configuration method, e.g. like below:
inpackage: true
name: studentStore
recursive: true
Hi, sorry to be terse but migrating to packages
has been thoroughly documented. It describes how you need additional configuration to specify where your mocks are placed. It seems you are simply lacking the right config.
Also we have a section in the docs specifically for this question: https://vektra.github.io/mockery/latest/configuration/#layouts
Indeed I've missed the dir
parameter from my config and I get the desired behaviour when I set it to "{{.InterfaceDir}}"
, thanks for the reply.
The reason for the confusion was that I was expecting the mock to be placed in the same package as my interface when inpackage: true
was set, regardless of the dir
parameter. It feels like dir
could be set to "{{.InterfaceDir}}"
automatically when inpackage: true
since if you place your mock in a different package then it's not in package anymore.
inpackage
can probably be removed at some point once we make mockery a bit smarter. It's needed to tell mockery whether or not you've placed the mocks in the same location as the original interface, as the imports and namespaces will be different. Mockery could probably determine this automatically. I just never got around to it, thus we're stuck with needing inpackage
for now.