github.com/go-kivik/kivik/v4@v4.3.2/mockdb/gen/templates/expectedtype.tmpl (about) 1 // Expected{{ .Name }} represents an expectation for a call to {{if .DBMethod}}DB.{{end}}{{.Name}}(). 2 type Expected{{ .Name }} struct { 3 commonExpectation 4 callback func({{ .DriverArgs }}) {{ .CallbackReturns }} 5 {{ .VariableDefinitions }} 6 } 7 {{ if .AcceptsOptions }} 8 // WithOptions sets the expected options for the call to {{if .DBMethod}}DB.{{end}}{{.Name}}(). 9 func (e *Expected{{.Name}}) WithOptions(options ...kivik.Option) *Expected{{.Name}} { 10 e.options = multiOptions{e.options, multiOptions(options)} 11 return e 12 } 13 {{ end }}// WillExecute sets a callback function to be called with any inputs to the 14 // original function. Any values returned by the callback will be returned as 15 // if generated by the driver. 16 func (e *Expected{{.Name}}) WillExecute(cb func({{ .DriverArgs }}) {{.CallbackReturns}}) *Expected{{.Name}} { 17 e.callback = cb 18 return e 19 } 20 {{ if ne (len .Returns) 0 }} 21 // WillReturn sets the values that will be returned by the call to {{if .DBMethod}}DB.{{end}}{{.Name}}(). 22 func (e *Expected{{.Name}}) WillReturn({{.ReturnTypes}}) *Expected{{.Name}} { 23 {{- range $i, $discard := .Returns }} 24 e.ret{{$i}} = ret{{$i}} 25 {{- end }} 26 return e 27 } 28 {{ end }} 29 {{- if .ReturnsError }} 30 // WillReturnError sets the error value that will be returned by the call to {{if .DBMethod}}DB.{{end}}{{.Name}}(). 31 func (e *Expected{{.Name}}) WillReturnError(err error) *Expected{{.Name}} { 32 e.err = err 33 return e 34 } 35 {{ end }} 36 {{- if .AcceptsContext }} 37 // WillDelay causes the call to {{if .DBMethod}}DB.{{end}}{{.Name}}() to delay. 38 func (e *Expected{{.Name}}) WillDelay(delay time.Duration) *Expected{{.Name}} { 39 e.delay = delay 40 return e 41 } 42 {{ end }} 43 44 func (e *Expected{{.Name}}) met({{$len := len .Accepts}}{{if eq $len 0}}_{{else}}ex{{end}} expectation) bool { 45 {{- .MetExpectations }} 46 return true 47 } 48 49 func (e *Expected{{.Name}}) method(v bool) string { 50 if !v { 51 return "{{if .DBMethod}}DB.{{end}}{{.Name}}()" 52 } 53 {{ .MethodArgs }} 54 }