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

Commit

Permalink
Merge pull request #28 from Clever/support-vendored-dependencies
Browse files Browse the repository at this point in the history
support mocking vendored dependencies
  • Loading branch information
balshetzer authored Feb 11, 2018
2 parents b3e60bc + 77f22c2 commit 58cd061
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mockgen/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ func typeFromType(t reflect.Type) (Type, error) {
}

if imp := t.PkgPath(); imp != "" {
// PkgPath might return a path that includes "vendor"
// These paths do not compile, so we need to remove everything
// up to and including "/vendor/"
// see https://github.com/golang/go/issues/12019
if i := strings.LastIndex(imp, "/vendor/"); i != -1 {
imp = imp[i+len("/vendor/"):]
}
return &NamedType{
Package: imp,
Type: t.Name(),
Expand Down
2 changes: 2 additions & 0 deletions mockgen/tests/vendor_dep/README.md
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).
3 changes: 3 additions & 0 deletions mockgen/tests/vendor_dep/doc.go
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
46 changes: 46 additions & 0 deletions mockgen/tests/vendor_dep/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions mockgen/tests/vendor_dep/vendor/a/a.go
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)
}
7 changes: 7 additions & 0 deletions mockgen/tests/vendor_dep/vendor_dep.go
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
}

0 comments on commit 58cd061

Please sign in to comment.