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
|
||||
// cannonical package name
|
||||
// canonical package name.
|
||||
func stripGopath(p string) string {
|
||||
for _, gopath := range gopaths() {
|
||||
p = strings.TrimPrefix(p, path.Join(gopath, "src")+"/")
|
||||
|
@ -1,9 +1,11 @@
|
||||
package moq
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/format"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"go/types"
|
||||
@ -114,10 +116,18 @@ func (m *Mocker) Mock(w io.Writer, name ...string) error {
|
||||
for pkgToImport := range m.imports {
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -196,10 +196,20 @@ func TestVendoredPackages(t *testing.T) {
|
||||
|
||||
// TestDotImports tests for https://github.com/matryer/moq/issues/21.
|
||||
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 {
|
||||
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")
|
||||
if err != nil {
|
||||
t.Fatalf("moq.New: %s", err)
|
||||
@ -210,7 +220,7 @@ func TestDotImports(t *testing.T) {
|
||||
t.Errorf("mock error: %s", err)
|
||||
}
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package channels
|
||||
|
||||
// Queue is a type to be sent down a channel.
|
||||
type Queue []string
|
||||
|
||||
// Queuer provides a channel example.
|
||||
type Queuer interface {
|
||||
Sub(topic string) (<-chan Queue, error)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package example
|
||||
|
||||
import "context"
|
||||
|
||||
// Person is a person.
|
||||
type Person struct {
|
||||
ID string
|
||||
Name string
|
||||
@ -9,6 +10,7 @@ type Person struct {
|
||||
Website string
|
||||
}
|
||||
|
||||
// PersonStore stores people.
|
||||
type PersonStore interface {
|
||||
Get(ctx context.Context, id string) (*Person, error)
|
||||
Create(ctx context.Context, person *Person, confirm bool) error
|
||||
|
Loading…
Reference in New Issue
Block a user