improved comments
This commit is contained in:
parent
295237bb43
commit
c9e7d899aa
@ -251,6 +251,12 @@ import (
|
|||||||
//
|
//
|
||||||
// // TODO: use mocked{{.InterfaceName}} in code that requires {{.InterfaceName}}
|
// // TODO: use mocked{{.InterfaceName}} in code that requires {{.InterfaceName}}
|
||||||
// // and then make assertions.
|
// // and then make assertions.
|
||||||
|
// //
|
||||||
|
// // Use the CallsTo structure to access details about what calls were made:
|
||||||
|
// //
|
||||||
|
// // if len(mocked{{.InterfaceName}}.CallsTo.MethodFunc) != 1 {
|
||||||
|
// // t.Errorf("expected 1 call there were %d", len(mocked{{.InterfaceName}}.CallsTo.MethodFunc))
|
||||||
|
// // }
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
type {{.InterfaceName}}Mock struct {
|
type {{.InterfaceName}}Mock struct {
|
||||||
@ -258,10 +264,14 @@ type {{.InterfaceName}}Mock struct {
|
|||||||
// {{.Name}}Func mocks the {{.Name}} method.
|
// {{.Name}}Func mocks the {{.Name}} method.
|
||||||
{{.Name}}Func func({{ .Arglist }}) {{.ReturnArglist}}
|
{{.Name}}Func func({{ .Arglist }}) {{.ReturnArglist}}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
// CallsTo gets counters for each of the methods indicating
|
// CallsTo tracks calls to the methods.
|
||||||
// how many times each one was called.
|
|
||||||
CallsTo struct {
|
CallsTo struct {
|
||||||
{{- range .Methods }}
|
// Enabled indicates that calls will be tracked.
|
||||||
|
//
|
||||||
|
// // don't track calls
|
||||||
|
// {{.InterfaceName}}Mock.CallsTo.Enabled = false
|
||||||
|
Enabled bool
|
||||||
|
{{ range .Methods }}
|
||||||
lock{{.Name}} sync.Mutex // protects {{ .Name }}
|
lock{{.Name}} sync.Mutex // protects {{ .Name }}
|
||||||
// {{ .Name }} holds details about calls to the {{.Name}} method.
|
// {{ .Name }} holds details about calls to the {{.Name}} method.
|
||||||
{{ .Name }} []struct {
|
{{ .Name }} []struct {
|
||||||
@ -278,6 +288,7 @@ 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 mock.CallsTo.Enabled {
|
||||||
mock.CallsTo.lock{{.Name}}.Lock()
|
mock.CallsTo.lock{{.Name}}.Lock()
|
||||||
mock.CallsTo.{{.Name}} = append(mock.CallsTo.{{.Name}}, struct{
|
mock.CallsTo.{{.Name}} = append(mock.CallsTo.{{.Name}}, struct{
|
||||||
{{- range .Params }}
|
{{- range .Params }}
|
||||||
@ -289,6 +300,7 @@ func (mock *{{$obj.InterfaceName}}Mock) {{.Name}}({{.Arglist}}) {{.ReturnArglist
|
|||||||
{{- end }}
|
{{- end }}
|
||||||
})
|
})
|
||||||
mock.CallsTo.lock{{.Name}}.Unlock()
|
mock.CallsTo.lock{{.Name}}.Unlock()
|
||||||
|
}
|
||||||
{{- if .ReturnArglist }}
|
{{- if .ReturnArglist }}
|
||||||
return mock.{{.Name}}Func({{.ArgCallList}})
|
return mock.{{.Name}}Func({{.ArgCallList}})
|
||||||
{{- else }}
|
{{- else }}
|
||||||
|
Loading…
Reference in New Issue
Block a user