Skip to content

Commit

Permalink
fix: element from the same package
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Jun 23, 2022
1 parent 90c6a5d commit 60d1651
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions mocktail.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const commentTagPattern = "// mocktail:"
// PackageDesc represent a package.
type PackageDesc struct {
PkgName string
PkgPath string
Imports map[string]struct{}
Interfaces []InterfaceDesc
}
Expand Down Expand Up @@ -58,7 +59,7 @@ func main() {
return
}

err = generate(model, moduleName)
err = generate(model)
if err != nil {
log.Fatal("generate", err)
}
Expand Down Expand Up @@ -139,6 +140,7 @@ func walk(modulePath, moduleName string) (map[string]PackageDesc, error) {

if packageDesc.PkgName == "" {
packageDesc.PkgName = lookup.Pkg().Name()
packageDesc.PkgPath = lookup.Pkg().Path()
}

interfaceDesc := InterfaceDesc{Name: interfaceName}
Expand Down Expand Up @@ -231,7 +233,7 @@ func getTypeImports(t types.Type) []string {
}
}

func generate(model map[string]PackageDesc, moduleName string) error {
func generate(model map[string]PackageDesc) error {
for fp, pkgDesc := range model {
buffer := bytes.NewBufferString("")

Expand All @@ -252,7 +254,7 @@ func generate(model map[string]PackageDesc, moduleName string) error {
signature := method.Type().(*types.Signature)

syrup := Syrup{
ModuleName: moduleName,
PkgPath: pkgDesc.PkgPath,
InterfaceName: interfaceDesc.Name,
Method: method,
Signature: signature,
Expand Down
4 changes: 2 additions & 2 deletions syrup.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (_c *{{ .InterfaceName | ToGoCamel }}{{ .MethodName }}Call) Maybe() *{{ .In

// Syrup generates method mocks and mock.Call wrapper.
type Syrup struct {
ModuleName string
PkgPath string
InterfaceName string
Method *types.Func
Signature *types.Signature
Expand Down Expand Up @@ -612,7 +612,7 @@ func (s Syrup) getTypeName(t types.Type, last bool) string {
}

if v.Obj() != nil && v.Obj().Pkg() != nil {
if v.Obj().Pkg().Path() == s.ModuleName {
if v.Obj().Pkg().Path() == s.PkgPath {
i := strings.Index(name, ".")
return name[i+1:]
}
Expand Down

0 comments on commit 60d1651

Please sign in to comment.