Skip to content
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

Configuration option inpackage is not functioning as expected #777

Closed
1 of 5 tasks
emreler opened this issue May 10, 2024 · 3 comments
Closed
1 of 5 tasks

Configuration option inpackage is not functioning as expected #777

emreler opened this issue May 10, 2024 · 3 comments

Comments

@emreler
Copy link

emreler commented May 10, 2024

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
  • brew
  • go install
  • Other: [specify]

Steps to Reproduce

  1. Use the package configuration method
  2. Create a go module, e.g. github.com/emreler/foo
  3. Define an interface in a subpackage, e.g. github.com/emreler/foo/bar
  4. Create a .mockery.yaml config file like provided below
  5. 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
@LandonTClipp
Copy link
Contributor

LandonTClipp commented May 10, 2024

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

@emreler
Copy link
Author

emreler commented May 13, 2024

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.

@LandonTClipp
Copy link
Contributor

LandonTClipp commented May 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants