Comments (11)
You're right, it would become more complex, but on the other hand, having it find the package in $GOPATH/src
when you're using vendoring is also confusing, and if you have an older, incompatible version of a library in $GOPATH/src
, counterfeiter would create the fake, but it wouldn't build, and it wouldn't be obvious why counterfeiter is generating the wrong fake.
I'll try to write some tests, but I don't know when I'll have time to do that. For now I've forked counterfeiter, because I need these fixes for a project I'm working on.
from counterfeiter.
Yeah I'd definitely love this behavior :)
from counterfeiter.
So if I understand the use case correctly here ...
There is a vendored library in your project, and it exports an interface. It's their interface that you want to generate a fake for?
I'm not totally opposed to supporting this behavior, but I am amazed at how the complexity of vendor paths and gopaths makes it hard to tell someone simply how counterfeiter
searches for code, when you give it a path name. It's getting very, very, very complicated.
One possible alternative to what you've suggested here would be to have your project define a type alias for the interface you want to mock. That way the interface would be in your project, and easier to find. From my own experience, and the teams within cloud foundry, the preferred Go coding style is to define interfaces closer to where you consume them, in the way I've described here.
from counterfeiter.
Yes.
from counterfeiter.
and just a quick note on the PR for this, #76 - I think this could be useful for other people, but I'm a little concerned about the difficulty of maintaining these changes.
Are you interested in backfilling some unit tests for the changes to the locator
package for PRs #74 and #76 ?
from counterfeiter.
Is there any progress in solving this?
from counterfeiter.
Just ran into this issue and your suggested type alias workaround isn't a solution. In my case, I'm pulling in two difference dependencies whose interfaces interact.
from counterfeiter.
Here is an ugly workaround to this problem:
//go:generate counterfeiter -o ./fakes/fake_interface.go ../vendor/github.com/user/library/pkg Interface
//go:generate gsed -i "s|<my-pkg>/vendor/||g" fakes/fake_interface.go
After this running go generate ./...
will generate the right fakes.
Note: gsed only works on osx (when gnu-sed is installed), if you want this to work on linux, use sed.
from counterfeiter.
I think this will be fixed by #94, please check out that PR.
from counterfeiter.
This does not seem to be working as expected.
Counterfeiter now uses golang.org/x/tools/go/packages
, which does not resolve vendored packages correctly for me. I have to specify the full vendored path, e.g. github.com/someuser/someproject/vendor/github.com/someotheruser/somelibrary.SomeType
. If I specify github.com/someotheruser/somelibrary.SomeType
, it'll fail if it's not in GOPATH, and if it's in GOPATH, I believe it will use that version, which is also incorrect.
from counterfeiter.
This is an issue with go/packages, there's workaround: golang/go#30289
from counterfeiter.
Related Issues (20)
- Support overriding destination package name and type naming template in "-generate" call HOT 5
- Support for DoThingsCallsOnCall(callCount, stub ...) similar to DoThingsReturnsOnCall(callCount)
- How to use shorthand generate directive for external packages? HOT 1
- cannot find GOROOT directory HOT 1
- Go 1.18 generics HOT 8
- cannot write tests in package being tested due to import cycle
- [CVE-2020-11022] Update of counterfeiter/v6 needed HOT 2
- Homebrew: Does not complete test on Go 1.20rc1 HOT 4
- disable CircleCI HOT 2
- cannot use json.Marshal(h) (value of type []byte) as driver.Value value in return statement HOT 1
- Support for callback func stub? HOT 1
- Cannot regenerate fakes if they are relied upon and deleted - go1.19.10 HOT 1
- About the latest release HOT 6
- Allow setting destination package name independent of directory name
- Excessive memory usage when generating multiple fakes with `counterfeiter:generate` directives.
- Counterfeiter does not generate private interface methods (used in `grpc-go`) HOT 1
- generation fails when interfaces are declared in a type block.
- Generate doesn't import packages referenced in type args
- Import cycle is not allowed in test
- Support Go 1.22 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from counterfeiter.