From 92c01adec91281a9109c95d1e64bb93b151700e8 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Thu, 6 Oct 2016 11:24:08 +0100 Subject: [PATCH] added test to prove variadic args aren't working --- example/example.go | 2 +- package/moq/moq_test.go | 31 ++++++++++++++++++++++-- package/moq/testdata/example/example.go | 15 ++++++++++++ package/moq/testdata/variadic/greeter.go | 8 ++++++ 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 package/moq/testdata/example/example.go create mode 100644 package/moq/testdata/variadic/greeter.go diff --git a/example/example.go b/example/example.go index 312652d..6ef1b04 100644 --- a/example/example.go +++ b/example/example.go @@ -2,7 +2,7 @@ package example import "context" -//go:generate moq PersonStore -out mockpersonstore_test.go +//go:generate moq -out mockpersonstore_test.go PersonStore type Person struct { ID string diff --git a/package/moq/moq_test.go b/package/moq/moq_test.go index 6a5d74b..2b85c3a 100644 --- a/package/moq/moq_test.go +++ b/package/moq/moq_test.go @@ -7,7 +7,7 @@ import ( ) func TestMoq(t *testing.T) { - m, err := New("../../example", "") + m, err := New("testdata/example", "") if err != nil { t.Errorf("moq.New: %s", err) } @@ -34,7 +34,7 @@ func TestMoq(t *testing.T) { } func TestMoqExplicitPackage(t *testing.T) { - m, err := New("../../example", "different") + m, err := New("testdata/example", "different") if err != nil { t.Errorf("moq.New: %s", err) } @@ -59,3 +59,30 @@ func TestMoqExplicitPackage(t *testing.T) { } } } + +// TestVeradicArguments tests to ensure variadic work as +// expected. +// see https://github.com/matryer/moq/issues/5 +func TestVariadicArguments(t *testing.T) { + m, err := New("testdata/variadic", "") + if err != nil { + t.Errorf("moq.New: %s", err) + } + var buf bytes.Buffer + err = m.Mock(&buf, "Greeter") + if err != nil { + t.Errorf("m.Mock: %s", err) + } + s := buf.String() + // assertions of things that should be mentioned + var strs = []string{ + "package variadic", + "type GreeterMock struct", + "GreetFunc func(ctx context.Context, names ...string) string", + } + for _, str := range strs { + if !strings.Contains(s, str) { + t.Errorf("expected but missing: \"%s\"", str) + } + } +} diff --git a/package/moq/testdata/example/example.go b/package/moq/testdata/example/example.go new file mode 100644 index 0000000..3adcbb8 --- /dev/null +++ b/package/moq/testdata/example/example.go @@ -0,0 +1,15 @@ +package example + +import "context" + +type Person struct { + ID string + Name string + Company string + Website string +} + +type PersonStore interface { + Get(ctx context.Context, id string) (*Person, error) + Create(ctx context.Context, person *Person, confirm bool) error +} diff --git a/package/moq/testdata/variadic/greeter.go b/package/moq/testdata/variadic/greeter.go new file mode 100644 index 0000000..44f746f --- /dev/null +++ b/package/moq/testdata/variadic/greeter.go @@ -0,0 +1,8 @@ +package variadic + +import "context" + +// Greeter greets people. +type Greeter interface { + Greet(ctx context.Context, names ...string) string +}