Fixes #12
This commit is contained in:
parent
9cb6c4999f
commit
9153bd984b
@ -235,7 +235,11 @@ func (mock *{{$obj.InterfaceName}}Mock) {{.Name}}({{.Arglist}}) {{.ReturnArglist
|
|||||||
if mock.{{.Name}}Func == nil {
|
if mock.{{.Name}}Func == nil {
|
||||||
panic("moq: {{$obj.InterfaceName}}Mock.{{.Name}}Func is nil but was just called")
|
panic("moq: {{$obj.InterfaceName}}Mock.{{.Name}}Func is nil but was just called")
|
||||||
}
|
}
|
||||||
|
{{ if .ReturnArglist }}
|
||||||
return mock.{{.Name}}Func({{.ArgCallList}})
|
return mock.{{.Name}}Func({{.ArgCallList}})
|
||||||
|
{{ else }}
|
||||||
|
mock.{{.Name}}Func({{.ArgCallList}})
|
||||||
|
{{ end }}
|
||||||
}
|
}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}`
|
{{ end -}}`
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1
package/moq/testdata/example/example.go
vendored
1
package/moq/testdata/example/example.go
vendored
@ -12,4 +12,5 @@ type Person struct {
|
|||||||
type PersonStore interface {
|
type PersonStore interface {
|
||||||
Get(ctx context.Context, id string) (*Person, error)
|
Get(ctx context.Context, id string) (*Person, error)
|
||||||
Create(ctx context.Context, person *Person, confirm bool) error
|
Create(ctx context.Context, person *Person, confirm bool) error
|
||||||
|
ClearCache(id string)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user