From df49857c18fa6a638f4ec8beaea7d2581b189fe4 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Tue, 11 Jul 2017 20:02:46 +0100 Subject: [PATCH] added vendor example --- main.go | 2 +- {package => pkg}/moq/importer.go | 0 {package => pkg}/moq/moq.go | 0 {package => pkg}/moq/moq_test.go | 16 +++++++++++++++- .../moq/testdata/channels/example.go | 0 {package => pkg}/moq/testdata/example/example.go | 0 {package => pkg}/moq/testdata/imports/one/one.go | 0 {package => pkg}/moq/testdata/imports/two/two.go | 2 +- .../moq/testdata/variadic/greeter.go | 0 pkg/moq/testdata/vendoring/user/user.go | 8 ++++++++ .../vendor/github.com/matryer/somerepo/code.go | 9 +++++++++ 11 files changed, 34 insertions(+), 3 deletions(-) rename {package => pkg}/moq/importer.go (100%) rename {package => pkg}/moq/moq.go (100%) rename {package => pkg}/moq/moq_test.go (92%) rename {package => pkg}/moq/testdata/channels/example.go (100%) rename {package => pkg}/moq/testdata/example/example.go (100%) rename {package => pkg}/moq/testdata/imports/one/one.go (100%) rename {package => pkg}/moq/testdata/imports/two/two.go (71%) rename {package => pkg}/moq/testdata/variadic/greeter.go (100%) create mode 100644 pkg/moq/testdata/vendoring/user/user.go create mode 100644 pkg/moq/testdata/vendoring/user/vendor/github.com/matryer/somerepo/code.go diff --git a/main.go b/main.go index d58d2fd..d525994 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import ( "io/ioutil" "os" - "github.com/matryer/moq/package/moq" + "github.com/matryer/moq/pkg/moq" ) func main() { diff --git a/package/moq/importer.go b/pkg/moq/importer.go similarity index 100% rename from package/moq/importer.go rename to pkg/moq/importer.go diff --git a/package/moq/moq.go b/pkg/moq/moq.go similarity index 100% rename from package/moq/moq.go rename to pkg/moq/moq.go diff --git a/package/moq/moq_test.go b/pkg/moq/moq_test.go similarity index 92% rename from package/moq/moq_test.go rename to pkg/moq/moq_test.go index 1fad8df..dee91f4 100644 --- a/package/moq/moq_test.go +++ b/pkg/moq/moq_test.go @@ -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()) +} diff --git a/package/moq/testdata/channels/example.go b/pkg/moq/testdata/channels/example.go similarity index 100% rename from package/moq/testdata/channels/example.go rename to pkg/moq/testdata/channels/example.go diff --git a/package/moq/testdata/example/example.go b/pkg/moq/testdata/example/example.go similarity index 100% rename from package/moq/testdata/example/example.go rename to pkg/moq/testdata/example/example.go diff --git a/package/moq/testdata/imports/one/one.go b/pkg/moq/testdata/imports/one/one.go similarity index 100% rename from package/moq/testdata/imports/one/one.go rename to pkg/moq/testdata/imports/one/one.go diff --git a/package/moq/testdata/imports/two/two.go b/pkg/moq/testdata/imports/two/two.go similarity index 71% rename from package/moq/testdata/imports/two/two.go rename to pkg/moq/testdata/imports/two/two.go index a7635a6..1ebba15 100644 --- a/package/moq/testdata/imports/two/two.go +++ b/pkg/moq/testdata/imports/two/two.go @@ -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. diff --git a/package/moq/testdata/variadic/greeter.go b/pkg/moq/testdata/variadic/greeter.go similarity index 100% rename from package/moq/testdata/variadic/greeter.go rename to pkg/moq/testdata/variadic/greeter.go diff --git a/pkg/moq/testdata/vendoring/user/user.go b/pkg/moq/testdata/vendoring/user/user.go new file mode 100644 index 0000000..798f104 --- /dev/null +++ b/pkg/moq/testdata/vendoring/user/user.go @@ -0,0 +1,8 @@ +package user + +import "github.com/matryer/somerepo" + +// Service does something good with computers. +type Service interface { + DoSomething(somerepo.SomeType) error +} diff --git a/pkg/moq/testdata/vendoring/user/vendor/github.com/matryer/somerepo/code.go b/pkg/moq/testdata/vendoring/user/vendor/github.com/matryer/somerepo/code.go new file mode 100644 index 0000000..706bf42 --- /dev/null +++ b/pkg/moq/testdata/vendoring/user/vendor/github.com/matryer/somerepo/code.go @@ -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 +}