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

Unnecessary import leading to incorrect with inpackage, keeptree and dir: "{{.InterfaceDir}}" #680

Closed
1 of 5 tasks
cedric-appdirect opened this issue Aug 1, 2023 · 4 comments

Comments

@cedric-appdirect
Copy link

Description

When using keeptree: True, inpackage: True and dir: "{{.InterfaceDir}}" together with interface that depend from each other, but from the same package, result in unnecessary import that prevent code from compiling.

Mockery Version

2.32.2

Golang Version

1.20.5

Installation Method

  • Binary Distribution
  • Docker
  • brew
  • go install
  • Other: [specify]

Steps to Reproduce

Example code:

package bug

type A interface {
}
type B interface {
  Create() A
}
type C interface {
  Call(A)
}

Will give the following result for B and C:

package bug

import (
   internalbug "internal/bug"
   mock "github.com/stretchr/testify/mock"
)

This is an internal package, I haven't tested if outside of the internal subdirectory would make any difference. Still the path specified in my yaml file match exactly the import line generated.

Expected Behavior

I would think it should be possible for mockery to detect that internalbug is actually the same as the current package and shouldn't be there (and use of it in the file too).

Actual Behavior

It generate those unnecessary reference to internalbug that get the compiler unhappy.

@cedric-appdirect
Copy link
Author

This behavior seems intended as this test exactly match this configuration: https://github.com/vektra/mockery/blob/master/pkg/generator.go#L160 . I guess I am misunderstanding something here on what those parameters means when used together.

@LandonTClipp
Copy link
Collaborator

LandonTClipp commented Aug 1, 2023

keeptree is not part of the new config parameters so I would remove that. Does it work it you remove it? It's not supported to use any of the legacy config options when using packages, only use the ones noted here: https://vektra.github.io/mockery/latest/configuration/#parameter-descriptions

@cedric-appdirect
Copy link
Author

Yes, it does work when removing keeptree and it was there just due to migrating to latest mockery. Maybe it would be good to generate a warning when using it with packages.

@LandonTClipp
Copy link
Collaborator

Excellent. You aren't the first one to be tripped up by that. I will think about ways to make the migration easier.

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