This commit is contained in:
Mat Ryer 2017-03-07 12:56:15 +00:00
parent 9cb6c4999f
commit 9153bd984b
3 changed files with 30 additions and 0 deletions

View File

@ -235,7 +235,11 @@ func (mock *{{$obj.InterfaceName}}Mock) {{.Name}}({{.Arglist}}) {{.ReturnArglist
if mock.{{.Name}}Func == nil {
panic("moq: {{$obj.InterfaceName}}Mock.{{.Name}}Func is nil but was just called")
}
{{ if .ReturnArglist }}
return mock.{{.Name}}Func({{.ArgCallList}})
{{ else }}
mock.{{.Name}}Func({{.ArgCallList}})
{{ end }}
}
{{ end -}}
{{ end -}}`

View File

@ -89,3 +89,28 @@ func TestVariadicArguments(t *testing.T) {
}
}
}
func TestNothingToReturn(t *testing.T) {
m, err := New("testdata/example", "")
if err != nil {
t.Errorf("moq.New: %s", err)
}
var buf bytes.Buffer
err = m.Mock(&buf, "PersonStore")
if err != nil {
t.Errorf("m.Mock: %s", err)
}
s := buf.String()
if strings.Contains(s, `return mock.ClearCacheFunc(id)`) {
t.Errorf("should not have return for items that have no return arguments")
}
// assertions of things that should be mentioned
var strs = []string{
"mock.ClearCacheFunc(id)",
}
for _, str := range strs {
if !strings.Contains(s, str) {
t.Errorf("expected but missing: \"%s\"", str)
}
}
}

View File

@ -12,4 +12,5 @@ type Person struct {
type PersonStore interface {
Get(ctx context.Context, id string) (*Person, error)
Create(ctx context.Context, person *Person, confirm bool) error
ClearCache(id string)
}