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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot generate fakes for types that use aliased internal types #174

Open
krishicks opened this issue Mar 26, 2021 · 7 comments
Open

Cannot generate fakes for types that use aliased internal types #174

krishicks opened this issue Mar 26, 2021 · 7 comments

Comments

@krishicks
Copy link

馃憢 I wanted to use counterfeiter to generate a fake that includes a Cadence workflow.Context, which is a type alias to internal.Context: https://github.com/uber-go/cadence-client/blob/0.9.1/workflow/context.go#L33

Creating a fake for the type that references workflow.Context results in the internal package being imported in the fake, which results in a compile error:

... use of internal package go.uber.org/cadence/internal not allowed

It would be great if counterfeiter created a fake for the type alias rather than the type being aliased.

This was tested on counterfeiter v6.3.0.

@krishicks
Copy link
Author

Related issue, where Cadence is aliasing internal interfaces:

uber-go/cadence-client#928
uber-go/cadence-client#929

@krishicks
Copy link
Author

I've found mockery also generates a fake that imports the internal package. However, gomock in its --source mode does not; it imports the workflow package.

joefitzgerald added a commit that referenced this issue Apr 1, 2021
- seems to work as expected
@joefitzgerald
Copy link
Collaborator

joefitzgerald commented Apr 1, 2021

@krishicks I attempted to reproduce your issue (with v6.4.0) and the tool worked as expected. I did update golang.org/x/tools to v0.1.0 between v6.3.0 and v6.4.0. Can you try using v6.4.0 and let me know if you're still experiencing the issue?

@joefitzgerald
Copy link
Collaborator

Closing, happy to reopen if it's still an issue using >= v6.4.0

@krishicks
Copy link
Author

krishicks commented Apr 6, 2021

This is still an issue with v6.4.1. I created a repo that shows the issue: https://github.com/krishicks/repro

See https://github.com/krishicks/repro/blob/master/reprofakes/fake_my_interface.go#L8. It's an internal package, but should be "go.uber.org/cadence/workflow".

@joefitzgerald joefitzgerald reopened this Apr 6, 2021
@joefitzgerald
Copy link
Collaborator

joefitzgerald commented Apr 19, 2021

@krishicks thanks for posting that; I now have a local reproduction, and I see the issue. I'm not certain how to fix it, because I think go/packages and/or go/types has no way to provide me the information I would need to generate the fake using the correct (aliased) type in the non-internal package.

I took a look at gopls and it seems like they are using the AST to figure this out (e.g. golang/go#37283).

joefitzgerald added a commit that referenced this issue Apr 19, 2021
joefitzgerald added a commit that referenced this issue Apr 19, 2021
@Skarlso
Copy link

Skarlso commented Dec 13, 2022

Hello @joefitzgerald :)

I bumped into this issue as well recently. My "solution" for now is a sed/// after the file is generated, which is obviously not an ideal solution. Did you look at the AST solution by any chance?

Cheers!

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

3 participants