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,17 +288,19 @@ 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")
|
||||||
}
|
}
|
||||||
mock.CallsTo.lock{{.Name}}.Lock()
|
if mock.CallsTo.Enabled {
|
||||||
mock.CallsTo.{{.Name}} = append(mock.CallsTo.{{.Name}}, struct{
|
mock.CallsTo.lock{{.Name}}.Lock()
|
||||||
{{- range .Params }}
|
mock.CallsTo.{{.Name}} = append(mock.CallsTo.{{.Name}}, struct{
|
||||||
{{ .Name | Exported }} {{ .Type }}
|
{{- range .Params }}
|
||||||
{{- end }}
|
{{ .Name | Exported }} {{ .Type }}
|
||||||
}{
|
{{- end }}
|
||||||
{{- range .Params }}
|
}{
|
||||||
{{ .Name | Exported }}: {{ .Name }},
|
{{- range .Params }}
|
||||||
{{- end }}
|
{{ .Name | Exported }}: {{ .Name }},
|
||||||
})
|
{{- 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