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

Commit 040104e

Browse files
committed
Modify mockgen for embed option when output package is same package
1 parent 7233f2a commit 040104e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mockgen/mockgen.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac
342342
g.packageMap[pth] = pkgName
343343
localNames[pkgName] = true
344344
}
345-
if *embed {
345+
if *embed && pkg.Name != *packageOut {
346346
g.packageMap[g.srcPackage] = pkg.Name
347347
}
348348

@@ -417,7 +417,11 @@ func (g *generator) GenerateMockInterface(pkgName string, intf *model.Interface,
417417
g.p("type %v%v struct {", mockType, longTp)
418418
g.in()
419419
if *embed {
420-
g.p("%v.%v", pkgName, intf.Name)
420+
if pkgName != *packageOut {
421+
g.p("%v.%v", pkgName, intf.Name)
422+
} else {
423+
g.p("%v", intf.Name)
424+
}
421425
}
422426
g.p("ctrl *gomock.Controller")
423427
g.p("recorder *%vMockRecorder%v", mockType, shortTp)

0 commit comments

Comments
 (0)