From 2ab8b1850cd543859032873b8b62ff658c3d32c1 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Sat, 26 Nov 2016 11:24:53 -0800 Subject: [PATCH] improved nil panics to include service name --- package/moq/moq.go | 3 ++- package/moq/moq_test.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package/moq/moq.go b/package/moq/moq.go index 83c5551..436579e 100644 --- a/package/moq/moq.go +++ b/package/moq/moq.go @@ -229,11 +229,12 @@ type {{.InterfaceName}}Mock struct { {{.Name}}Func func({{ .Arglist }}) {{.ReturnArglist}} {{- end }} } + {{ range .Methods }} // {{.Name}} calls {{.Name}}Func. func (mock *{{$obj.InterfaceName}}Mock) {{.Name}}({{.Arglist}}) {{.ReturnArglist}} { 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}}) } diff --git a/package/moq/moq_test.go b/package/moq/moq_test.go index e69d4aa..b4dbf68 100644 --- a/package/moq/moq_test.go +++ b/package/moq/moq_test.go @@ -25,6 +25,8 @@ func TestMoq(t *testing.T) { "GetFunc func(ctx context.Context, id string) (*Person, error)", "func (mock *PersonStoreMock) Create(ctx context.Context, person *Person, confirm bool) 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 { if !strings.Contains(s, str) {