Merge branch 'master' into fix-emptyinterfaces
This commit is contained in:
commit
d17151fc4e
@ -177,7 +177,7 @@ func newImporter(source string) types.Importer {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// stripGopath teks the directory to a package and remove the gopath to get the
|
// stripGopath teks the directory to a package and remove the gopath to get the
|
||||||
// cannonical package name
|
// canonical package name.
|
||||||
func stripGopath(p string) string {
|
func stripGopath(p string) string {
|
||||||
for _, gopath := range gopaths() {
|
for _, gopath := range gopaths() {
|
||||||
p = strings.TrimPrefix(p, path.Join(gopath, "src")+"/")
|
p = strings.TrimPrefix(p, path.Join(gopath, "src")+"/")
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package moq
|
package moq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
|
"go/format"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
@ -114,10 +116,18 @@ func (m *Mocker) Mock(w io.Writer, name ...string) error {
|
|||||||
for pkgToImport := range m.imports {
|
for pkgToImport := range m.imports {
|
||||||
doc.Imports = append(doc.Imports, pkgToImport)
|
doc.Imports = append(doc.Imports, pkgToImport)
|
||||||
}
|
}
|
||||||
err := m.tmpl.Execute(w, doc)
|
var buf bytes.Buffer
|
||||||
|
err := m.tmpl.Execute(&buf, doc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
formatted, err := format.Source(buf.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("go/format: %s", err)
|
||||||
|
}
|
||||||
|
if _, err := w.Write(formatted); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,10 +196,20 @@ func TestVendoredPackages(t *testing.T) {
|
|||||||
|
|
||||||
// TestDotImports tests for https://github.com/matryer/moq/issues/21.
|
// TestDotImports tests for https://github.com/matryer/moq/issues/21.
|
||||||
func TestDotImports(t *testing.T) {
|
func TestDotImports(t *testing.T) {
|
||||||
err := os.Chdir("testpackages/dotimport")
|
preDir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Getwd: %s", err)
|
||||||
|
}
|
||||||
|
err = os.Chdir("testpackages/dotimport")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Chdir: %s", err)
|
t.Errorf("Chdir: %s", err)
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
err := os.Chdir(preDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Chdir back: %s", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
m, err := New(".", "moqtest_test")
|
m, err := New(".", "moqtest_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("moq.New: %s", err)
|
t.Fatalf("moq.New: %s", err)
|
||||||
@ -210,7 +220,7 @@ func TestDotImports(t *testing.T) {
|
|||||||
t.Errorf("mock error: %s", err)
|
t.Errorf("mock error: %s", err)
|
||||||
}
|
}
|
||||||
s := buf.String()
|
s := buf.String()
|
||||||
if !strings.Contains(s, `"github.com/matryer/moq/pkg/moq/testpackages/dotimport"`) {
|
if !strings.Contains(s, `/moq/pkg/moq/testpackages/dotimport"`) {
|
||||||
t.Error("contains invalid dot import")
|
t.Error("contains invalid dot import")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package channels
|
package channels
|
||||||
|
|
||||||
|
// Queue is a type to be sent down a channel.
|
||||||
type Queue []string
|
type Queue []string
|
||||||
|
|
||||||
|
// Queuer provides a channel example.
|
||||||
type Queuer interface {
|
type Queuer interface {
|
||||||
Sub(topic string) (<-chan Queue, error)
|
Sub(topic string) (<-chan Queue, error)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package example
|
|||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
|
// Person is a person.
|
||||||
type Person struct {
|
type Person struct {
|
||||||
ID string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
@ -9,6 +10,7 @@ type Person struct {
|
|||||||
Website string
|
Website string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PersonStore stores people.
|
||||||
type PersonStore interface {
|
type PersonStore interface {
|
||||||
Get(ctx context.Context, id string) (*Person, error)
|
Get(ctx context.Context, id string) (*Person, error)
|
||||||
Create(ctx context.Context, person *Person, confirm bool) error
|
Create(ctx context.Context, person *Person, confirm bool) error
|
||||||
|
Loading…
Reference in New Issue
Block a user