[TEST] check missing package name for packages with the same name

This commit is contained in:
Frederik Vosberg 2018-07-10 16:22:49 +02:00
parent f4ed779510
commit fc06e5c36a
3 changed files with 29 additions and 0 deletions

View File

@ -271,3 +271,20 @@ func TestGoGenerateVendoredPackages(t *testing.T) {
t.Error("contains vendor directory in import path") t.Error("contains vendor directory in import path")
} }
} }
func TestImportedPackageWithSameName(t *testing.T) {
m, err := New("testpackages/samenameimport", "")
if err != nil {
t.Fatalf("moq.New: %s", err)
}
var buf bytes.Buffer
err = m.Mock(&buf, "Example")
if err != nil {
t.Errorf("mock error: %s", err)
}
s := buf.String()
if !strings.Contains(s, `"samenameimport.A"`) {
t.Error("missing samenameimport.A to address the struct A from the external package samenameimport")
}
t.Logf("\n\n%s\n\n", s)
}

View File

@ -0,0 +1,8 @@
package samename
import samename "github.com/matryer/moq/pkg/moq/testpackages/samenameimport/samenameimport"
// Example is used to test issues with packages, which import another package with the same name
type Example interface {
Do(a samename.A) error
}

View File

@ -0,0 +1,4 @@
package samename
// The A is used in the parent package as a dependency
type A struct{}