improvements
This commit is contained in:
parent
124baf32f3
commit
67ac3093f9
@ -63,7 +63,7 @@ func (m *Mocker) Mock(w io.Writer, name ...string) error {
|
||||
}
|
||||
iiface := iface.Type().Underlying().(*types.Interface).Complete()
|
||||
obj := &obj{
|
||||
Name: n,
|
||||
InterfaceName: n,
|
||||
}
|
||||
for i := 0; i < iiface.NumMethods(); i++ {
|
||||
meth := iiface.Method(i)
|
||||
@ -105,7 +105,7 @@ func extractArgs(list *types.Tuple, nameFormat string) []*param {
|
||||
}
|
||||
|
||||
type obj struct {
|
||||
Name string
|
||||
InterfaceName string
|
||||
Methods []*method
|
||||
}
|
||||
type method struct {
|
||||
@ -159,31 +159,31 @@ package todo
|
||||
|
||||
// AUTOGENERATED BY MOQ
|
||||
// github.com/matryer/moq
|
||||
{{ range .Objs }}
|
||||
// {{.Name}}Mock is a mock implementation of {{.Name}}.
|
||||
{{ range $i, $obj := .Objs }}
|
||||
// {{.InterfaceName}}Mock is a mock implementation of {{.InterfaceName}}
|
||||
// generated by github.com/matryer/moq.
|
||||
//
|
||||
// func TestSomethingThatUses{{.Name}}(t *testing.T) {
|
||||
// func TestSomethingThatUses{{.InterfaceName}}(t *testing.T) {
|
||||
//
|
||||
// // make and configure a mocked {{.Name}}
|
||||
// mocked{{.Name}} := {{.Name}}Mock{
|
||||
// {{ range .Methods }}{{.Name}}Func: func({{ .Arglist }}) {{.ReturnArglist}} {
|
||||
// // make and configure a mocked {{.InterfaceName}}
|
||||
// mocked{{.InterfaceName}} := &{{.InterfaceName}}Mock{ {{ range .Methods }}
|
||||
// {{.Name}}Func: func({{ .Arglist }}) {{.ReturnArglist}} {
|
||||
// panic("TODO: mock out the {{.Name}} function")
|
||||
// },
|
||||
// {{end}}
|
||||
// },{{- end }}
|
||||
// }
|
||||
//
|
||||
// // TODO: use mocked{{.Name}} in code that requires {{.Name}}
|
||||
// // TODO: use mocked{{.InterfaceName}} in code that requires {{.InterfaceName}}
|
||||
//
|
||||
// }
|
||||
type {{.Name}}Mock struct {
|
||||
{{ range .Methods }}
|
||||
type {{.InterfaceName}}Mock struct {
|
||||
{{- range .Methods }}
|
||||
// {{.Name}}Func mocks the {{.Name}} function.
|
||||
{{.Name}}Func func({{ .Arglist }}) {{.ReturnArglist}}
|
||||
{{ end }}}
|
||||
{{- end }}
|
||||
}
|
||||
{{ range .Methods }}
|
||||
// {{.Name}} calls the mocked {{.Name}}Func function or panics if it was
|
||||
// not set.
|
||||
func (mock {{.Name}}Mock) {{.Name}}({{ .Arglist }}) {{.ReturnArglist}} {
|
||||
// {{.Name}} calls {{.Name}}Func.
|
||||
func (mock *{{$obj.InterfaceName}}Mock) {{.Name}}({{.Arglist}}) {{.ReturnArglist}} {
|
||||
if mock.{{.Name}} == nil {
|
||||
panic("moq: {{.Name}}Func is nil but was just called")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user