improved nil panics to include service name

This commit is contained in:
Mat Ryer 2016-11-26 11:24:53 -08:00
parent b76739db6c
commit 2ab8b1850c
2 changed files with 4 additions and 1 deletions

View File

@ -229,11 +229,12 @@ type {{.InterfaceName}}Mock struct {
{{.Name}}Func func({{ .Arglist }}) {{.ReturnArglist}} {{.Name}}Func func({{ .Arglist }}) {{.ReturnArglist}}
{{- end }} {{- end }}
} }
{{ range .Methods }} {{ range .Methods }}
// {{.Name}} calls {{.Name}}Func. // {{.Name}} calls {{.Name}}Func.
func (mock *{{$obj.InterfaceName}}Mock) {{.Name}}({{.Arglist}}) {{.ReturnArglist}} { func (mock *{{$obj.InterfaceName}}Mock) {{.Name}}({{.Arglist}}) {{.ReturnArglist}} {
if mock.{{.Name}}Func == nil { if mock.{{.Name}}Func == nil {
panic("moq: {{.Name}}Func is nil but was just called") panic("moq: {{$obj.InterfaceName}}Mock.{{.Name}}Func is nil but was just called")
} }
return mock.{{.Name}}Func({{.ArgCallList}}) return mock.{{.Name}}Func({{.ArgCallList}})
} }

View File

@ -25,6 +25,8 @@ func TestMoq(t *testing.T) {
"GetFunc func(ctx context.Context, id string) (*Person, error)", "GetFunc func(ctx context.Context, id string) (*Person, error)",
"func (mock *PersonStoreMock) Create(ctx context.Context, person *Person, confirm bool) error", "func (mock *PersonStoreMock) Create(ctx context.Context, person *Person, confirm bool) error",
"func (mock *PersonStoreMock) Get(ctx context.Context, id string) (*Person, error)", "func (mock *PersonStoreMock) Get(ctx context.Context, id string) (*Person, error)",
"panic(\"moq: PersonStoreMock.CreateFunc is nil but was just called\")",
"panic(\"moq: PersonStoreMock.GetFunc is nil but was just called\")",
} }
for _, str := range strs { for _, str := range strs {
if !strings.Contains(s, str) { if !strings.Contains(s, str) {