-
Notifications
You must be signed in to change notification settings - Fork 606
support mocking vendored dependencies #28
support mocking vendored dependencies #28
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! Company name: Clever. |
CLAs look good, thanks! |
If a |
do we need to update something in this PR for approve it? |
mockgen/reflect.go
Outdated
@@ -41,8 +41,13 @@ func Reflect(importPath string, symbols []string) (*model.Package, error) { | |||
|
|||
progPath := *execOnly | |||
if *execOnly == "" { | |||
// Put program in working directory to pick up packages in vendor/ during build | |||
wDir, err := os.Getwd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a non-starter for anyone using this where the source files might be read-only. We might need to resort to this only when needed (e.g. if there's vendoring involved).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsymonds re-reading the vendor spec I'm not sure there's an easy way to do that...the vendor
directory could exist on a completely different subtree in the filesystem, so it's not as simple as looking for the existence of a vendor
directory in the working directory.
Caused by golang/mock#28 Signed-off-by: Chris Brown <cbrown@pivotal.io>
What's the next steps for this PR? Just ran into this again. Looks like a new commit went up but can't tell immediately from the GitHub UI if that happened before or after the feedback. |
* Switch to fork that supports generating mocks for vendored dependencies (golang/mock#28) * Install vendored mockgen before generating mocks * Do not try to find files when no directories are found
Any update on this? |
Any updates? It looks like this also blocks the ability to vendorize |
Any upgrade on this, using the following is not super healthy for my brain :D
|
+1 |
@rgarcia, looks like there are conflicts in mockgen/reflect.go. Would you be willing to bring this up to date with master and address any unaddressed review feedback? Thanks! |
Any update on this? I am also facing an issue that this PR most likely fixes. |
I don't believe @rgarcia is available since 2016 to work on this. Is it possible for someone else with write access to merge this with the latest master, resolve any conflicts and merge it. Reading the comments it appears many people have had this issue and this PR fixes it. |
Thanks @rgarcia! Didn't realize there was another PR for this. |
@rgarcia I am really sorry to bother you about this, but the PR (#99) you referenced did not resolve this issue. I just tested this PR (#28) and it did resolve my issue with the incorrect path to the vendor. I humbly request that if it is possible to reopen this PR, review it and merge it. Thank you. This PR fixes this issue: #30 |
#99 addresses mocking interfaces within vendored libraries. This PR addresses dependencies of mocks that are vendored, and the fact that the resulting mock code contains the illegal
package vendor_dep
//go:generate mockgen github.com/golang/mock/mockgen/tests/vendor_dep VendorsDep
package vendor_dep
import "a"
type VendorsDep interface {
Foo() a.Ifc
}
package a
type Ifc interface {
A(string) string
B(int) int
C(chan int) chan int
D(interface{})
E(map[string]interface{})
F([]float64)
} Note that we're not mocking the vendored interface, we're mocking an interface that depends on a vendored type. The mockgen output has the following header: [15:26:56] ~/go/src/github.com/golang/mock/mockgen/tests/vendor_dep $ go generate .
// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/golang/mock/mockgen/tests/vendor_dep (interfaces: VendorsDep)
// Package mock_vendor_dep is a generated GoMock package.
package mock_vendor_dep
import (
gomock "github.com/golang/mock/gomock"
a "github.com/golang/mock/mockgen/tests/vendor_dep/vendor/a"
reflect "reflect"
) The |
Thank you @kaedys for the explanation between the two PRs. I am not sure what the procedure is now that this PR is closed. |
Sorry for the confusion, I can reopen. |
@rgarcia Is it okay if I merge the latest master into this PR so it's up to date. I did it locally and there were no conflicts. Then we can see if it can be merged. |
- Generate temporary program in current directory tree to pick up vendored dependencies during build - Clean up the return of `PkgPath` according to the advice of rsc here golang/go#12019 (comment)
I went ahead and rebased |
@balshetzer Is it possible for you to take a look at this PR and see if it can be merged. This fixes this issue #30 |
I can confirm the fix works too |
Thanks for bringing this PR up-to-date. I'll take a look shortly. |
FWIW we get around this issue by using the
|
@rgarcia Interesting. Thanks! I am hoping this PR gets merged so I don’t have to manually update the generated mocks or do workarounds. @balshetzer - Any update on the PR review and merge? |
Make setup and predictable builds easier for contributors by locking to a set of dependencies. Some of the dependencies have been locked to specific commits on master in order to accomodate projects that do not ship releases often such as cobra and gomock (see spf13/cobra#259 for details). - Change mockgen commands to use a -source flag to explicitly point to the files in vendor for generating mocks. This, for some reason, fixes a bug in gomock whereby it uses the vendor path as the import path which breaks some dependencies. See golang/mock#28 for more details.
Doesn't the |
@balshetzer - Any update on this being merged? Thanks! |
Would it be possible for you to add a test case to verify that this fixes the problem? |
@rgarcia could we use the test @kaedys mentioned in this comment: #28 (comment) to fulfill @balshetzer 's request? |
added a test in 77f22c2 |
@balshetzer A test was added by @rgarcia - Can this PR be reviewed and merged? Thanks! |
PkgPath
according to the advice of rsc here reflect: PkgPath returns un-importable path go#12019 (comment)This fixes #4
The files I used to manually test this are here: https://gist.github.com/rgarcia/cf553169c4832543a0a9