added test to prove variadic args aren't working

This commit is contained in:
Mat Ryer 2016-10-06 11:24:08 +01:00
parent b050476316
commit 92c01adec9
4 changed files with 53 additions and 3 deletions

View File

@ -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

View File

@ -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)
}
}
}

15
package/moq/testdata/example/example.go vendored Normal file
View File

@ -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
}

View File

@ -0,0 +1,8 @@
package variadic
import "context"
// Greeter greets people.
type Greeter interface {
Greet(ctx context.Context, names ...string) string
}