This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 605
support mocking vendored dependencies #28
Merged
balshetzer
merged 2 commits into
golang:master
from
Clever:support-vendored-dependencies
Feb 11, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Test for [Issue#4](https://github.com/golang/mock/issues/4). | ||
Also see discussion on [#28](https://github.com/golang/mock/pull/28). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package vendor_dep | ||
|
||
//go:generate mockgen -package vendor_dep -destination mock.go github.com/golang/mock/mockgen/tests/vendor_dep VendorsDep |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package a | ||
|
||
type Ifc interface { | ||
A(string) string | ||
B(int) int | ||
C(chan int) chan int | ||
D(interface{}) | ||
E(map[string]interface{}) | ||
F([]float64) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package vendor_dep | ||
|
||
import "a" | ||
|
||
type VendorsDep interface { | ||
Foo() a.Ifc | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As the referenced bug says, PkgPath is not very well-defined. If we're going to address this, we should cope with /internal/ dirs too.
I wonder if this transformation should be happening later. Or if this should be in a library somewhere else. Surely gomock isn't the only program around that wants to handle vendored import paths?
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.
I'm not familiar with the
internal/
directory problem--could you elaborate? Is it necessary to address that in this PR?I did some searches and didn't find a library for this. IMO it's such a small piece of logic a library feels like overkill.
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.
internal/
directories can only be accessed by packages in or descending from the directory immediately above theinternal/
directory. It was a predecessor to the vendoring experiment started in Go 1.5. Here's the details:https://golang.org/doc/go1.4#internalpackages
https://docs.google.com/document/d/1e8kOo3r51b2BWtTs_1uADIA5djfXhPT36s6eHVRIvaU/edit?pref=2&pli=1
Mechanically, it works similar, except without the import path eliding that vendoring added. Where package
github.com/foo
, when vendored, is imported asgithub.com/foo
, if placed in the internal directory instead, it would have to be imported as, for example,github.com/bar/internal/github.com/foo
. However, like the vendored situation, it would only be accessible to thatbar
package and its subordinates. Main difference is that, ifgithub.com/foo
isn't present in the project tree, instead of falling back to the$GOPATH/src
location to check for an alternate version (like vendoring does), the internal one will throw a compile time error about the package being missing.It also differs slightly on scope. If you have this:
Then importing
"foo"
in A would importsrc/foo
and importing it in B would importsrc/B/internal/foo
. However, importing"bar"
in either A or B would importsrc/bar
. Importingsrc/B/internal/bar
would import exactly that in B, but if that same import line were in A, the compiler would instead throw an erroruse of internal package not allowed
, since it is trying to access an internal package while outside the scope allowed for that internal package (which is B and its descendants)