added vendor example

This commit is contained in:
Mat Ryer 2017-07-11 20:02:46 +01:00
parent be1d7ca86c
commit df49857c18
11 changed files with 34 additions and 3 deletions

View File

@ -9,7 +9,7 @@ import (
"io/ioutil"
"os"
"github.com/matryer/moq/package/moq"
"github.com/matryer/moq/pkg/moq"
)
func main() {

View File

@ -2,6 +2,7 @@ package moq
import (
"bytes"
"log"
"strings"
"testing"
)
@ -153,7 +154,7 @@ func TestImports(t *testing.T) {
s := buf.String()
var strs = []string{
` "sync"`,
` "github.com/matryer/moq/package/moq/testdata/imports/one"`,
` "github.com/matryer/moq/pkg/moq/testdata/imports/one"`,
}
for _, str := range strs {
if !strings.Contains(s, str) {
@ -171,3 +172,16 @@ func TestTemplateFuncs(t *testing.T) {
t.Errorf("exported didn't work: %s", fn("var"))
}
}
func TestVendoredPackages(t *testing.T) {
m, err := New("testdata/vendoring/user", "")
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)
}
log.Println(buf.String())
}

View File

@ -1,7 +1,7 @@
package two
import (
"github.com/matryer/moq/package/moq/testdata/imports/one"
"github.com/matryer/moq/pkg/moq/testdata/imports/one"
)
// DoSomething does something.

View File

@ -0,0 +1,8 @@
package user
import "github.com/matryer/somerepo"
// Service does something good with computers.
type Service interface {
DoSomething(somerepo.SomeType) error
}

View File

@ -0,0 +1,9 @@
// Package somerepo is a vendored package to test how moq deals with
// packages in the vendor package.
package somerepo
// SomeType is just some old type.
type SomeType struct {
// Truth indicates whether true is true or not. Computers.
Truth bool
}