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

Commit 42764bf

Browse files
committed
Fix a bug introduced in bdab667 that broke mocking interfaces with vendored dependencies in source mode.
1 parent c4148b8 commit 42764bf

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

mockgen/parse.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,13 @@ func importsOfFile(file *ast.File) map[string]string {
444444
pkg, err := build.Import(importPath, "", 0)
445445
if err != nil {
446446
// Fallback to import path suffix. Note that this is uncertain.
447-
log.Printf("failed to import package by path %s: %s - fallback to import path suffix", importPath, err.Error())
448447
_, last := path.Split(importPath)
449448
// If the last path component has dots, the first dot-delimited
450449
// field is used as the name.
451450
pkgName = strings.SplitN(last, ".", 2)[0]
451+
} else {
452+
pkgName = pkg.Name
452453
}
453-
pkgName = pkg.Name
454454
}
455455

456456
if _, ok := m[pkgName]; ok {

mockgen/tests/vendor_dep/source_mock_package/mock.go

+46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)