Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 58cd061

Browse files
authored
Merge pull request #28 from Clever/support-vendored-dependencies
support mocking vendored dependencies
2 parents b3e60bc + 77f22c2 commit 58cd061

File tree

6 files changed

+75
-0
lines changed

6 files changed

+75
-0
lines changed

mockgen/model/model.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,13 @@ func typeFromType(t reflect.Type) (Type, error) {
354354
}
355355

356356
if imp := t.PkgPath(); imp != "" {
357+
// PkgPath might return a path that includes "vendor"
358+
// These paths do not compile, so we need to remove everything
359+
// up to and including "/vendor/"
360+
// see https://github.com/golang/go/issues/12019
361+
if i := strings.LastIndex(imp, "/vendor/"); i != -1 {
362+
imp = imp[i+len("/vendor/"):]
363+
}
357364
return &NamedType{
358365
Package: imp,
359366
Type: t.Name(),

mockgen/tests/vendor_dep/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Test for [Issue#4](https://github.com/golang/mock/issues/4).
2+
Also see discussion on [#28](https://github.com/golang/mock/pull/28).

mockgen/tests/vendor_dep/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package vendor_dep
2+
3+
//go:generate mockgen -package vendor_dep -destination mock.go github.com/golang/mock/mockgen/tests/vendor_dep VendorsDep

mockgen/tests/vendor_dep/mock.go

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package a
2+
3+
type Ifc interface {
4+
A(string) string
5+
B(int) int
6+
C(chan int) chan int
7+
D(interface{})
8+
E(map[string]interface{})
9+
F([]float64)
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package vendor_dep
2+
3+
import "a"
4+
5+
type VendorsDep interface {
6+
Foo() a.Ifc
7+
}

0 commit comments

Comments
 (0)