Single dot imports explicitly not-included - fixes #21
This commit is contained in:
parent
1b59660688
commit
879118f880
@ -120,6 +120,9 @@ func (m *Mocker) packageQualifier(pkg *types.Package) string {
|
|||||||
if m.pkgName == pkg.Name() {
|
if m.pkgName == pkg.Name() {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
if pkg.Path() == "." {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
m.imports[pkg.Path()] = true
|
m.imports[pkg.Path()] = true
|
||||||
return pkg.Name()
|
return pkg.Name()
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package moq
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -192,3 +193,24 @@ func TestVendoredPackages(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestDotImports tests for https://github.com/matryer/moq/issues/21.
|
||||||
|
func TestDotImports(t *testing.T) {
|
||||||
|
err := os.Chdir("testpackages/issue-21")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Chdir: %s", err)
|
||||||
|
}
|
||||||
|
m, err := New(".", "moqtest_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("moq.New: %s", err)
|
||||||
|
}
|
||||||
|
var buf bytes.Buffer
|
||||||
|
err = m.Mock(&buf, "Service")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("mock error: %s", err)
|
||||||
|
}
|
||||||
|
s := buf.String()
|
||||||
|
if strings.Contains(s, `"."`) {
|
||||||
|
t.Error("contains invalid dot import")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
14
pkg/moq/testpackages/issue-21/service.go
Normal file
14
pkg/moq/testpackages/issue-21/service.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Package moqtest is just a package to try getting started with moq without the overhead of a real package
|
||||||
|
package moqtest
|
||||||
|
|
||||||
|
//go:generate moq -out service_moq_test.go -pkg moqtest_test . Service
|
||||||
|
|
||||||
|
// Service is the interface which should be mocked by moq
|
||||||
|
type Service interface {
|
||||||
|
User(ID string) (User, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// User is just a struct for testing
|
||||||
|
type User struct {
|
||||||
|
Name string
|
||||||
|
}
|
10
pkg/moq/testpackages/issue-21/service_test.go
Normal file
10
pkg/moq/testpackages/issue-21/service_test.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package moqtest_test
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestServiceMock(t *testing.T) {
|
||||||
|
// Here I want to use the ServiceMock
|
||||||
|
|
||||||
|
service := ServiceMock{}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user