mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
updating github.com/golang/mock to v1.2.0
This commit is contained in:
parent
0861b3f30f
commit
03c222ca09
4
go.mod
4
go.mod
@ -65,7 +65,7 @@ require (
|
|||||||
github.com/godbus/dbus v4.1.0+incompatible
|
github.com/godbus/dbus v4.1.0+incompatible
|
||||||
github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415
|
github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415
|
||||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903
|
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903
|
||||||
github.com/golang/mock v0.0.0-20160127222235-bd3c8e81be01
|
github.com/golang/mock v1.2.0
|
||||||
github.com/golang/protobuf v1.2.0
|
github.com/golang/protobuf v1.2.0
|
||||||
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450 // indirect
|
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450 // indirect
|
||||||
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995 // indirect
|
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995 // indirect
|
||||||
@ -275,7 +275,7 @@ replace (
|
|||||||
github.com/gogo/protobuf => github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415
|
github.com/gogo/protobuf => github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415
|
||||||
github.com/golang/glog => github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
|
github.com/golang/glog => github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
|
||||||
github.com/golang/groupcache => github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903
|
github.com/golang/groupcache => github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903
|
||||||
github.com/golang/mock => github.com/golang/mock v0.0.0-20160127222235-bd3c8e81be01
|
github.com/golang/mock => github.com/golang/mock v1.2.0
|
||||||
github.com/golang/protobuf => github.com/golang/protobuf v1.2.0
|
github.com/golang/protobuf => github.com/golang/protobuf v1.2.0
|
||||||
github.com/golangplus/bytes => github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450
|
github.com/golangplus/bytes => github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450
|
||||||
github.com/golangplus/fmt => github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995
|
github.com/golangplus/fmt => github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995
|
||||||
|
4
go.sum
4
go.sum
@ -157,8 +157,8 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekf
|
|||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903 h1:LbsanbbD6LieFkXbj9YNNBupiGHJgFeLpO0j0Fza1h8=
|
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903 h1:LbsanbbD6LieFkXbj9YNNBupiGHJgFeLpO0j0Fza1h8=
|
||||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
github.com/golang/mock v0.0.0-20160127222235-bd3c8e81be01 h1:rtnkE5nwSSDcZrbt4gcVsFPeSXXe7Nq2vCn9DBb0Y8I=
|
github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk=
|
||||||
github.com/golang/mock v0.0.0-20160127222235-bd3c8e81be01/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450 h1:7xqw01UYS+KCI25bMrPxwNYkSns2Db1ziQPpVq99FpE=
|
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450 h1:7xqw01UYS+KCI25bMrPxwNYkSns2Db1ziQPpVq99FpE=
|
||||||
|
310
vendor/github.com/golang/mock/gomock/call.go
generated
vendored
310
vendor/github.com/golang/mock/gomock/call.go
generated
vendored
@ -17,17 +17,19 @@ package gomock
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call represents an expected call to a mock.
|
// Call represents an expected call to a mock.
|
||||||
type Call struct {
|
type Call struct {
|
||||||
t TestReporter // for triggering test failures on invalid call setup
|
t TestHelper // for triggering test failures on invalid call setup
|
||||||
|
|
||||||
receiver interface{} // the receiver of the method call
|
receiver interface{} // the receiver of the method call
|
||||||
method string // the name of the method
|
method string // the name of the method
|
||||||
|
methodType reflect.Type // the type of the method
|
||||||
args []Matcher // the args
|
args []Matcher // the args
|
||||||
rets []interface{} // the return values (if any)
|
origin string // file and line number of call setup
|
||||||
|
|
||||||
preReqs []*Call // prerequisite calls
|
preReqs []*Call // prerequisite calls
|
||||||
|
|
||||||
@ -36,9 +38,42 @@ type Call struct {
|
|||||||
|
|
||||||
numCalls int // actual number made
|
numCalls int // actual number made
|
||||||
|
|
||||||
// Actions
|
// actions are called when this Call is called. Each action gets the args and
|
||||||
doFunc reflect.Value
|
// can set the return values by returning a non-nil slice. Actions run in the
|
||||||
setArgs map[int]reflect.Value
|
// order they are created.
|
||||||
|
actions []func([]interface{}) []interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// newCall creates a *Call. It requires the method type in order to support
|
||||||
|
// unexported methods.
|
||||||
|
func newCall(t TestHelper, receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
// TODO: check arity, types.
|
||||||
|
margs := make([]Matcher, len(args))
|
||||||
|
for i, arg := range args {
|
||||||
|
if m, ok := arg.(Matcher); ok {
|
||||||
|
margs[i] = m
|
||||||
|
} else if arg == nil {
|
||||||
|
// Handle nil specially so that passing a nil interface value
|
||||||
|
// will match the typed nils of concrete args.
|
||||||
|
margs[i] = Nil()
|
||||||
|
} else {
|
||||||
|
margs[i] = Eq(arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
origin := callerInfo(3)
|
||||||
|
actions := []func([]interface{}) []interface{}{func([]interface{}) []interface{} {
|
||||||
|
// Synthesize the zero value for each of the return args' types.
|
||||||
|
rets := make([]interface{}, methodType.NumOut())
|
||||||
|
for i := 0; i < methodType.NumOut(); i++ {
|
||||||
|
rets[i] = reflect.Zero(methodType.Out(i)).Interface()
|
||||||
|
}
|
||||||
|
return rets
|
||||||
|
}}
|
||||||
|
return &Call{t: t, receiver: receiver, method: method, methodType: methodType,
|
||||||
|
args: margs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnyTimes allows the expectation to be called 0 or more times
|
// AnyTimes allows the expectation to be called 0 or more times
|
||||||
@ -67,19 +102,67 @@ func (c *Call) MaxTimes(n int) *Call {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do declares the action to run when the call is matched.
|
// DoAndReturn declares the action to run when the call is matched.
|
||||||
|
// The return values from this function are returned by the mocked function.
|
||||||
// It takes an interface{} argument to support n-arity functions.
|
// It takes an interface{} argument to support n-arity functions.
|
||||||
func (c *Call) Do(f interface{}) *Call {
|
func (c *Call) DoAndReturn(f interface{}) *Call {
|
||||||
// TODO: Check arity and types here, rather than dying badly elsewhere.
|
// TODO: Check arity and types here, rather than dying badly elsewhere.
|
||||||
c.doFunc = reflect.ValueOf(f)
|
v := reflect.ValueOf(f)
|
||||||
|
|
||||||
|
c.addAction(func(args []interface{}) []interface{} {
|
||||||
|
vargs := make([]reflect.Value, len(args))
|
||||||
|
ft := v.Type()
|
||||||
|
for i := 0; i < len(args); i++ {
|
||||||
|
if args[i] != nil {
|
||||||
|
vargs[i] = reflect.ValueOf(args[i])
|
||||||
|
} else {
|
||||||
|
// Use the zero value for the arg.
|
||||||
|
vargs[i] = reflect.Zero(ft.In(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vrets := v.Call(vargs)
|
||||||
|
rets := make([]interface{}, len(vrets))
|
||||||
|
for i, ret := range vrets {
|
||||||
|
rets[i] = ret.Interface()
|
||||||
|
}
|
||||||
|
return rets
|
||||||
|
})
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do declares the action to run when the call is matched. The function's
|
||||||
|
// return values are ignored to retain backward compatibility. To use the
|
||||||
|
// return values call DoAndReturn.
|
||||||
|
// It takes an interface{} argument to support n-arity functions.
|
||||||
|
func (c *Call) Do(f interface{}) *Call {
|
||||||
|
// TODO: Check arity and types here, rather than dying badly elsewhere.
|
||||||
|
v := reflect.ValueOf(f)
|
||||||
|
|
||||||
|
c.addAction(func(args []interface{}) []interface{} {
|
||||||
|
vargs := make([]reflect.Value, len(args))
|
||||||
|
ft := v.Type()
|
||||||
|
for i := 0; i < len(args); i++ {
|
||||||
|
if args[i] != nil {
|
||||||
|
vargs[i] = reflect.ValueOf(args[i])
|
||||||
|
} else {
|
||||||
|
// Use the zero value for the arg.
|
||||||
|
vargs[i] = reflect.Zero(ft.In(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v.Call(vargs)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return declares the values to be returned by the mocked function call.
|
||||||
func (c *Call) Return(rets ...interface{}) *Call {
|
func (c *Call) Return(rets ...interface{}) *Call {
|
||||||
mt := c.methodType()
|
c.t.Helper()
|
||||||
|
|
||||||
|
mt := c.methodType
|
||||||
if len(rets) != mt.NumOut() {
|
if len(rets) != mt.NumOut() {
|
||||||
c.t.Fatalf("wrong number of arguments to Return for %T.%v: got %d, want %d",
|
c.t.Fatalf("wrong number of arguments to Return for %T.%v: got %d, want %d [%s]",
|
||||||
c.receiver, c.method, len(rets), mt.NumOut())
|
c.receiver, c.method, len(rets), mt.NumOut(), c.origin)
|
||||||
}
|
}
|
||||||
for i, ret := range rets {
|
for i, ret := range rets {
|
||||||
if got, want := reflect.TypeOf(ret), mt.Out(i); got == want {
|
if got, want := reflect.TypeOf(ret), mt.Out(i); got == want {
|
||||||
@ -90,8 +173,8 @@ func (c *Call) Return(rets ...interface{}) *Call {
|
|||||||
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
|
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
|
||||||
// ok
|
// ok
|
||||||
default:
|
default:
|
||||||
c.t.Fatalf("argument %d to Return for %T.%v is nil, but %v is not nillable",
|
c.t.Fatalf("argument %d to Return for %T.%v is nil, but %v is not nillable [%s]",
|
||||||
i, c.receiver, c.method, want)
|
i, c.receiver, c.method, want, c.origin)
|
||||||
}
|
}
|
||||||
} else if got.AssignableTo(want) {
|
} else if got.AssignableTo(want) {
|
||||||
// Assignable type relation. Make the assignment now so that the generated code
|
// Assignable type relation. Make the assignment now so that the generated code
|
||||||
@ -100,31 +183,36 @@ func (c *Call) Return(rets ...interface{}) *Call {
|
|||||||
v.Set(reflect.ValueOf(ret))
|
v.Set(reflect.ValueOf(ret))
|
||||||
rets[i] = v.Interface()
|
rets[i] = v.Interface()
|
||||||
} else {
|
} else {
|
||||||
c.t.Fatalf("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v",
|
c.t.Fatalf("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s]",
|
||||||
i, c.receiver, c.method, got, want)
|
i, c.receiver, c.method, got, want, c.origin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.rets = rets
|
c.addAction(func([]interface{}) []interface{} {
|
||||||
|
return rets
|
||||||
|
})
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Times declares the exact number of times a function call is expected to be executed.
|
||||||
func (c *Call) Times(n int) *Call {
|
func (c *Call) Times(n int) *Call {
|
||||||
c.minCalls, c.maxCalls = n, n
|
c.minCalls, c.maxCalls = n, n
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetArg declares an action that will set the nth argument's value,
|
// SetArg declares an action that will set the nth argument's value,
|
||||||
// indirected through a pointer.
|
// indirected through a pointer. Or, in the case of a slice, SetArg
|
||||||
|
// will copy value's elements into the nth argument.
|
||||||
func (c *Call) SetArg(n int, value interface{}) *Call {
|
func (c *Call) SetArg(n int, value interface{}) *Call {
|
||||||
if c.setArgs == nil {
|
c.t.Helper()
|
||||||
c.setArgs = make(map[int]reflect.Value)
|
|
||||||
}
|
mt := c.methodType
|
||||||
mt := c.methodType()
|
|
||||||
// TODO: This will break on variadic methods.
|
// TODO: This will break on variadic methods.
|
||||||
// We will need to check those at invocation time.
|
// We will need to check those at invocation time.
|
||||||
if n < 0 || n >= mt.NumIn() {
|
if n < 0 || n >= mt.NumIn() {
|
||||||
c.t.Fatalf("SetArg(%d, ...) called for a method with %d args", n, mt.NumIn())
|
c.t.Fatalf("SetArg(%d, ...) called for a method with %d args [%s]",
|
||||||
|
n, mt.NumIn(), c.origin)
|
||||||
}
|
}
|
||||||
// Permit setting argument through an interface.
|
// Permit setting argument through an interface.
|
||||||
// In the interface case, we don't (nay, can't) check the type here.
|
// In the interface case, we don't (nay, can't) check the type here.
|
||||||
@ -133,14 +221,28 @@ func (c *Call) SetArg(n int, value interface{}) *Call {
|
|||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
dt := at.Elem()
|
dt := at.Elem()
|
||||||
if vt := reflect.TypeOf(value); !vt.AssignableTo(dt) {
|
if vt := reflect.TypeOf(value); !vt.AssignableTo(dt) {
|
||||||
c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v", n, vt, dt)
|
c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]",
|
||||||
|
n, vt, dt, c.origin)
|
||||||
}
|
}
|
||||||
case reflect.Interface:
|
case reflect.Interface:
|
||||||
// nothing to do
|
// nothing to do
|
||||||
|
case reflect.Slice:
|
||||||
|
// nothing to do
|
||||||
default:
|
default:
|
||||||
c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface type %v", n, at)
|
c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice type %v [%s]",
|
||||||
|
n, at, c.origin)
|
||||||
}
|
}
|
||||||
c.setArgs[n] = reflect.ValueOf(value)
|
|
||||||
|
c.addAction(func(args []interface{}) []interface{} {
|
||||||
|
v := reflect.ValueOf(value)
|
||||||
|
switch reflect.TypeOf(args[n]).Kind() {
|
||||||
|
case reflect.Slice:
|
||||||
|
setSlice(args[n], v)
|
||||||
|
default:
|
||||||
|
reflect.ValueOf(args[n]).Elem().Set(v)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,19 +258,20 @@ func (c *Call) isPreReq(other *Call) bool {
|
|||||||
|
|
||||||
// After declares that the call may only match after preReq has been exhausted.
|
// After declares that the call may only match after preReq has been exhausted.
|
||||||
func (c *Call) After(preReq *Call) *Call {
|
func (c *Call) After(preReq *Call) *Call {
|
||||||
|
c.t.Helper()
|
||||||
|
|
||||||
|
if c == preReq {
|
||||||
|
c.t.Fatalf("A call isn't allowed to be its own prerequisite")
|
||||||
|
}
|
||||||
if preReq.isPreReq(c) {
|
if preReq.isPreReq(c) {
|
||||||
msg := fmt.Sprintf(
|
c.t.Fatalf("Loop in call order: %v is a prerequisite to %v (possibly indirectly).", c, preReq)
|
||||||
"Loop in call order: %v is a prerequisite to %v (possibly indirectly).",
|
|
||||||
c, preReq,
|
|
||||||
)
|
|
||||||
panic(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.preReqs = append(c.preReqs, preReq)
|
c.preReqs = append(c.preReqs, preReq)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true iff the minimum number of calls have been made.
|
// Returns true if the minimum number of calls have been made.
|
||||||
func (c *Call) satisfied() bool {
|
func (c *Call) satisfied() bool {
|
||||||
return c.numCalls >= c.minCalls
|
return c.numCalls >= c.minCalls
|
||||||
}
|
}
|
||||||
@ -184,31 +287,108 @@ func (c *Call) String() string {
|
|||||||
args[i] = arg.String()
|
args[i] = arg.String()
|
||||||
}
|
}
|
||||||
arguments := strings.Join(args, ", ")
|
arguments := strings.Join(args, ", ")
|
||||||
return fmt.Sprintf("%T.%v(%s)", c.receiver, c.method, arguments)
|
return fmt.Sprintf("%T.%v(%s) %s", c.receiver, c.method, arguments, c.origin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests if the given call matches the expected call.
|
// Tests if the given call matches the expected call.
|
||||||
func (c *Call) matches(args []interface{}) bool {
|
// If yes, returns nil. If no, returns error with message explaining why it does not match.
|
||||||
|
func (c *Call) matches(args []interface{}) error {
|
||||||
|
if !c.methodType.IsVariadic() {
|
||||||
if len(args) != len(c.args) {
|
if len(args) != len(c.args) {
|
||||||
return false
|
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d",
|
||||||
|
c.origin, len(args), len(c.args))
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, m := range c.args {
|
for i, m := range c.args {
|
||||||
if !m.Matches(args[i]) {
|
if !m.Matches(args[i]) {
|
||||||
return false
|
return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v",
|
||||||
|
c.origin, strconv.Itoa(i), args[i], m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if len(c.args) < c.methodType.NumIn()-1 {
|
||||||
|
return fmt.Errorf("Expected call at %s has the wrong number of matchers. Got: %d, want: %d",
|
||||||
|
c.origin, len(c.args), c.methodType.NumIn()-1)
|
||||||
|
}
|
||||||
|
if len(c.args) != c.methodType.NumIn() && len(args) != len(c.args) {
|
||||||
|
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d",
|
||||||
|
c.origin, len(args), len(c.args))
|
||||||
|
}
|
||||||
|
if len(args) < len(c.args)-1 {
|
||||||
|
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: greater than or equal to %d",
|
||||||
|
c.origin, len(args), len(c.args)-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, m := range c.args {
|
||||||
|
if i < c.methodType.NumIn()-1 {
|
||||||
|
// Non-variadic args
|
||||||
|
if !m.Matches(args[i]) {
|
||||||
|
return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v",
|
||||||
|
c.origin, strconv.Itoa(i), args[i], m)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// The last arg has a possibility of a variadic argument, so let it branch
|
||||||
|
|
||||||
|
// sample: Foo(a int, b int, c ...int)
|
||||||
|
if i < len(c.args) && i < len(args) {
|
||||||
|
if m.Matches(args[i]) {
|
||||||
|
// Got Foo(a, b, c) want Foo(matcherA, matcherB, gomock.Any())
|
||||||
|
// Got Foo(a, b, c) want Foo(matcherA, matcherB, someSliceMatcher)
|
||||||
|
// Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC)
|
||||||
|
// Got Foo(a, b) want Foo(matcherA, matcherB)
|
||||||
|
// Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The number of actual args don't match the number of matchers,
|
||||||
|
// or the last matcher is a slice and the last arg is not.
|
||||||
|
// If this function still matches it is because the last matcher
|
||||||
|
// matches all the remaining arguments or the lack of any.
|
||||||
|
// Convert the remaining arguments, if any, into a slice of the
|
||||||
|
// expected type.
|
||||||
|
vargsType := c.methodType.In(c.methodType.NumIn() - 1)
|
||||||
|
vargs := reflect.MakeSlice(vargsType, 0, len(args)-i)
|
||||||
|
for _, arg := range args[i:] {
|
||||||
|
vargs = reflect.Append(vargs, reflect.ValueOf(arg))
|
||||||
|
}
|
||||||
|
if m.Matches(vargs.Interface()) {
|
||||||
|
// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, gomock.Any())
|
||||||
|
// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, someSliceMatcher)
|
||||||
|
// Got Foo(a, b) want Foo(matcherA, matcherB, gomock.Any())
|
||||||
|
// Got Foo(a, b) want Foo(matcherA, matcherB, someEmptySliceMatcher)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// Wrong number of matchers or not match. Fail.
|
||||||
|
// Got Foo(a, b) want Foo(matcherA, matcherB, matcherC, matcherD)
|
||||||
|
// Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC, matcherD)
|
||||||
|
// Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD, matcherE)
|
||||||
|
// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, matcherC, matcherD)
|
||||||
|
// Got Foo(a, b, c) want Foo(matcherA, matcherB)
|
||||||
|
return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v",
|
||||||
|
c.origin, strconv.Itoa(i), args[i:], c.args[i])
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that all prerequisite calls have been satisfied.
|
// Check that all prerequisite calls have been satisfied.
|
||||||
for _, preReqCall := range c.preReqs {
|
for _, preReqCall := range c.preReqs {
|
||||||
if !preReqCall.satisfied() {
|
if !preReqCall.satisfied() {
|
||||||
return false
|
return fmt.Errorf("Expected call at %s doesn't have a prerequisite call satisfied:\n%v\nshould be called before:\n%v",
|
||||||
|
c.origin, preReqCall, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
// Check that the call is not exhausted.
|
||||||
|
if c.exhausted() {
|
||||||
|
return fmt.Errorf("Expected call at %s has already been called the max number of times.", c.origin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// dropPrereqs tells the expected Call to not re-check prerequite calls any
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// dropPrereqs tells the expected Call to not re-check prerequisite calls any
|
||||||
// longer, and to return its current set.
|
// longer, and to return its current set.
|
||||||
func (c *Call) dropPrereqs() (preReqs []*Call) {
|
func (c *Call) dropPrereqs() (preReqs []*Call) {
|
||||||
preReqs = c.preReqs
|
preReqs = c.preReqs
|
||||||
@ -216,48 +396,9 @@ func (c *Call) dropPrereqs() (preReqs []*Call) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Call) call(args []interface{}) (rets []interface{}, action func()) {
|
func (c *Call) call(args []interface{}) []func([]interface{}) []interface{} {
|
||||||
c.numCalls++
|
c.numCalls++
|
||||||
|
return c.actions
|
||||||
// Actions
|
|
||||||
if c.doFunc.IsValid() {
|
|
||||||
doArgs := make([]reflect.Value, len(args))
|
|
||||||
ft := c.doFunc.Type()
|
|
||||||
for i := 0; i < ft.NumIn(); i++ {
|
|
||||||
if args[i] != nil {
|
|
||||||
doArgs[i] = reflect.ValueOf(args[i])
|
|
||||||
} else {
|
|
||||||
// Use the zero value for the arg.
|
|
||||||
doArgs[i] = reflect.Zero(ft.In(i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
action = func() { c.doFunc.Call(doArgs) }
|
|
||||||
}
|
|
||||||
for n, v := range c.setArgs {
|
|
||||||
reflect.ValueOf(args[n]).Elem().Set(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
rets = c.rets
|
|
||||||
if rets == nil {
|
|
||||||
// Synthesize the zero value for each of the return args' types.
|
|
||||||
mt := c.methodType()
|
|
||||||
rets = make([]interface{}, mt.NumOut())
|
|
||||||
for i := 0; i < mt.NumOut(); i++ {
|
|
||||||
rets[i] = reflect.Zero(mt.Out(i)).Interface()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Call) methodType() reflect.Type {
|
|
||||||
recv := reflect.ValueOf(c.receiver)
|
|
||||||
for i := 0; i < recv.Type().NumMethod(); i++ {
|
|
||||||
if recv.Type().Method(i).Name == c.method {
|
|
||||||
return recv.Method(i).Type()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panic(fmt.Sprintf("gomock: failed finding method %s on %T", c.method, c.receiver))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InOrder declares that the given calls should occur in order.
|
// InOrder declares that the given calls should occur in order.
|
||||||
@ -266,3 +407,14 @@ func InOrder(calls ...*Call) {
|
|||||||
calls[i].After(calls[i-1])
|
calls[i].After(calls[i-1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setSlice(arg interface{}, v reflect.Value) {
|
||||||
|
va := reflect.ValueOf(arg)
|
||||||
|
for i := 0; i < v.Len(); i++ {
|
||||||
|
va.Index(i).Set(v.Index(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Call) addAction(action func([]interface{}) []interface{}) {
|
||||||
|
c.actions = append(c.actions, action)
|
||||||
|
}
|
||||||
|
106
vendor/github.com/golang/mock/gomock/callset.go
generated
vendored
106
vendor/github.com/golang/mock/gomock/callset.go
generated
vendored
@ -14,63 +14,95 @@
|
|||||||
|
|
||||||
package gomock
|
package gomock
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
// callSet represents a set of expected calls, indexed by receiver and method
|
// callSet represents a set of expected calls, indexed by receiver and method
|
||||||
// name.
|
// name.
|
||||||
type callSet map[interface{}]map[string][]*Call
|
type callSet struct {
|
||||||
|
// Calls that are still expected.
|
||||||
|
expected map[callSetKey][]*Call
|
||||||
|
// Calls that have been exhausted.
|
||||||
|
exhausted map[callSetKey][]*Call
|
||||||
|
}
|
||||||
|
|
||||||
|
// callSetKey is the key in the maps in callSet
|
||||||
|
type callSetKey struct {
|
||||||
|
receiver interface{}
|
||||||
|
fname string
|
||||||
|
}
|
||||||
|
|
||||||
|
func newCallSet() *callSet {
|
||||||
|
return &callSet{make(map[callSetKey][]*Call), make(map[callSetKey][]*Call)}
|
||||||
|
}
|
||||||
|
|
||||||
// Add adds a new expected call.
|
// Add adds a new expected call.
|
||||||
func (cs callSet) Add(call *Call) {
|
func (cs callSet) Add(call *Call) {
|
||||||
methodMap, ok := cs[call.receiver]
|
key := callSetKey{call.receiver, call.method}
|
||||||
if !ok {
|
m := cs.expected
|
||||||
methodMap = make(map[string][]*Call)
|
if call.exhausted() {
|
||||||
cs[call.receiver] = methodMap
|
m = cs.exhausted
|
||||||
}
|
}
|
||||||
methodMap[call.method] = append(methodMap[call.method], call)
|
m[key] = append(m[key], call)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove removes an expected call.
|
// Remove removes an expected call.
|
||||||
func (cs callSet) Remove(call *Call) {
|
func (cs callSet) Remove(call *Call) {
|
||||||
methodMap, ok := cs[call.receiver]
|
key := callSetKey{call.receiver, call.method}
|
||||||
if !ok {
|
calls := cs.expected[key]
|
||||||
return
|
for i, c := range calls {
|
||||||
}
|
|
||||||
sl := methodMap[call.method]
|
|
||||||
for i, c := range sl {
|
|
||||||
if c == call {
|
if c == call {
|
||||||
// quick removal; we don't need to maintain call order
|
// maintain order for remaining calls
|
||||||
if len(sl) > 1 {
|
cs.expected[key] = append(calls[:i], calls[i+1:]...)
|
||||||
sl[i] = sl[len(sl)-1]
|
cs.exhausted[key] = append(cs.exhausted[key], call)
|
||||||
}
|
|
||||||
methodMap[call.method] = sl[:len(sl)-1]
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindMatch searches for a matching call. Returns nil if no call matched.
|
// FindMatch searches for a matching call. Returns error with explanation message if no call matched.
|
||||||
func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) *Call {
|
func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) (*Call, error) {
|
||||||
methodMap, ok := cs[receiver]
|
key := callSetKey{receiver, method}
|
||||||
if !ok {
|
|
||||||
return nil
|
// Search through the expected calls.
|
||||||
|
expected := cs.expected[key]
|
||||||
|
var callsErrors bytes.Buffer
|
||||||
|
for _, call := range expected {
|
||||||
|
err := call.matches(args)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(&callsErrors, "\n%v", err)
|
||||||
|
} else {
|
||||||
|
return call, nil
|
||||||
}
|
}
|
||||||
calls, ok := methodMap[method]
|
|
||||||
if !ok {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search through the unordered set of calls expected on a method on a
|
// If we haven't found a match then search through the exhausted calls so we
|
||||||
// receiver.
|
// get useful error messages.
|
||||||
|
exhausted := cs.exhausted[key]
|
||||||
|
for _, call := range exhausted {
|
||||||
|
if err := call.matches(args); err != nil {
|
||||||
|
fmt.Fprintf(&callsErrors, "\n%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(expected)+len(exhausted) == 0 {
|
||||||
|
fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf(callsErrors.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failures returns the calls that are not satisfied.
|
||||||
|
func (cs callSet) Failures() []*Call {
|
||||||
|
failures := make([]*Call, 0, len(cs.expected))
|
||||||
|
for _, calls := range cs.expected {
|
||||||
for _, call := range calls {
|
for _, call := range calls {
|
||||||
// A call should not normally still be here if exhausted,
|
if !call.satisfied() {
|
||||||
// but it can happen if, for instance, .Times(0) was used.
|
failures = append(failures, call)
|
||||||
// Pretend the call doesn't match.
|
|
||||||
if call.exhausted() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if call.matches(args) {
|
|
||||||
return call
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return failures
|
||||||
}
|
}
|
||||||
|
152
vendor/github.com/golang/mock/gomock/controller.go
generated
vendored
152
vendor/github.com/golang/mock/gomock/controller.go
generated
vendored
@ -55,7 +55,13 @@
|
|||||||
// - Handle different argument/return types (e.g. ..., chan, map, interface).
|
// - Handle different argument/return types (e.g. ..., chan, map, interface).
|
||||||
package gomock
|
package gomock
|
||||||
|
|
||||||
import "sync"
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"runtime"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
// A TestReporter is something that can be used to report test failures.
|
// A TestReporter is something that can be used to report test failures.
|
||||||
// It is satisfied by the standard library's *testing.T.
|
// It is satisfied by the standard library's *testing.T.
|
||||||
@ -64,53 +70,109 @@ type TestReporter interface {
|
|||||||
Fatalf(format string, args ...interface{})
|
Fatalf(format string, args ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestHelper is a TestReporter that has the Helper method. It is satisfied
|
||||||
|
// by the standard library's *testing.T.
|
||||||
|
type TestHelper interface {
|
||||||
|
TestReporter
|
||||||
|
Helper()
|
||||||
|
}
|
||||||
|
|
||||||
// A Controller represents the top-level control of a mock ecosystem.
|
// A Controller represents the top-level control of a mock ecosystem.
|
||||||
// It defines the scope and lifetime of mock objects, as well as their expectations.
|
// It defines the scope and lifetime of mock objects, as well as their expectations.
|
||||||
// It is safe to call Controller's methods from multiple goroutines.
|
// It is safe to call Controller's methods from multiple goroutines.
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
|
// T should only be called within a generated mock. It is not intended to
|
||||||
|
// be used in user code and may be changed in future versions. T is the
|
||||||
|
// TestReporter passed in when creating the Controller via NewController.
|
||||||
|
// If the TestReporter does not implment a TestHelper it will be wrapped
|
||||||
|
// with a nopTestHelper.
|
||||||
|
T TestHelper
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
t TestReporter
|
expectedCalls *callSet
|
||||||
expectedCalls callSet
|
finished bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewController(t TestReporter) *Controller {
|
func NewController(t TestReporter) *Controller {
|
||||||
|
h, ok := t.(TestHelper)
|
||||||
|
if !ok {
|
||||||
|
h = nopTestHelper{t}
|
||||||
|
}
|
||||||
|
|
||||||
return &Controller{
|
return &Controller{
|
||||||
t: t,
|
T: h,
|
||||||
expectedCalls: make(callSet),
|
expectedCalls: newCallSet(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type cancelReporter struct {
|
||||||
|
TestHelper
|
||||||
|
cancel func()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *cancelReporter) Errorf(format string, args ...interface{}) {
|
||||||
|
r.TestHelper.Errorf(format, args...)
|
||||||
|
}
|
||||||
|
func (r *cancelReporter) Fatalf(format string, args ...interface{}) {
|
||||||
|
defer r.cancel()
|
||||||
|
r.TestHelper.Fatalf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithContext returns a new Controller and a Context, which is cancelled on any
|
||||||
|
// fatal failure.
|
||||||
|
func WithContext(ctx context.Context, t TestReporter) (*Controller, context.Context) {
|
||||||
|
h, ok := t.(TestHelper)
|
||||||
|
if !ok {
|
||||||
|
h = nopTestHelper{t}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
return NewController(&cancelReporter{h, cancel}), ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
type nopTestHelper struct {
|
||||||
|
TestReporter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h nopTestHelper) Helper() {}
|
||||||
|
|
||||||
func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call {
|
func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call {
|
||||||
// TODO: check arity, types.
|
ctrl.T.Helper()
|
||||||
margs := make([]Matcher, len(args))
|
|
||||||
for i, arg := range args {
|
recv := reflect.ValueOf(receiver)
|
||||||
if m, ok := arg.(Matcher); ok {
|
for i := 0; i < recv.Type().NumMethod(); i++ {
|
||||||
margs[i] = m
|
if recv.Type().Method(i).Name == method {
|
||||||
} else if arg == nil {
|
return ctrl.RecordCallWithMethodType(receiver, method, recv.Method(i).Type(), args...)
|
||||||
// Handle nil specially so that passing a nil interface value
|
|
||||||
// will match the typed nils of concrete args.
|
|
||||||
margs[i] = Nil()
|
|
||||||
} else {
|
|
||||||
margs[i] = Eq(arg)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ctrl.T.Fatalf("gomock: failed finding method %s on %T", method, receiver)
|
||||||
|
panic("unreachable")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call {
|
||||||
|
ctrl.T.Helper()
|
||||||
|
|
||||||
|
call := newCall(ctrl.T, receiver, method, methodType, args...)
|
||||||
|
|
||||||
ctrl.mu.Lock()
|
ctrl.mu.Lock()
|
||||||
defer ctrl.mu.Unlock()
|
defer ctrl.mu.Unlock()
|
||||||
|
|
||||||
call := &Call{t: ctrl.t, receiver: receiver, method: method, args: margs, minCalls: 1, maxCalls: 1}
|
|
||||||
|
|
||||||
ctrl.expectedCalls.Add(call)
|
ctrl.expectedCalls.Add(call)
|
||||||
|
|
||||||
return call
|
return call
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} {
|
func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} {
|
||||||
|
ctrl.T.Helper()
|
||||||
|
|
||||||
|
// Nest this code so we can use defer to make sure the lock is released.
|
||||||
|
actions := func() []func([]interface{}) []interface{} {
|
||||||
|
ctrl.T.Helper()
|
||||||
ctrl.mu.Lock()
|
ctrl.mu.Lock()
|
||||||
defer ctrl.mu.Unlock()
|
defer ctrl.mu.Unlock()
|
||||||
|
|
||||||
expected := ctrl.expectedCalls.FindMatch(receiver, method, args)
|
expected, err := ctrl.expectedCalls.FindMatch(receiver, method, args)
|
||||||
if expected == nil {
|
if err != nil {
|
||||||
ctrl.t.Fatalf("no matching expected call: %T.%v(%v)", receiver, method, args)
|
origin := callerInfo(2)
|
||||||
|
ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, args, origin, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Two things happen here:
|
// Two things happen here:
|
||||||
@ -121,28 +183,34 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf
|
|||||||
ctrl.expectedCalls.Remove(preReqCall)
|
ctrl.expectedCalls.Remove(preReqCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
rets, action := expected.call(args)
|
actions := expected.call(args)
|
||||||
if expected.exhausted() {
|
if expected.exhausted() {
|
||||||
ctrl.expectedCalls.Remove(expected)
|
ctrl.expectedCalls.Remove(expected)
|
||||||
}
|
}
|
||||||
|
return actions
|
||||||
|
}()
|
||||||
|
|
||||||
// Don't hold the lock while doing the call's action (if any)
|
var rets []interface{}
|
||||||
// so that actions may execute concurrently.
|
for _, action := range actions {
|
||||||
// We use the deferred Unlock to capture any panics that happen above;
|
if r := action(args); r != nil {
|
||||||
// here we add a deferred Lock to balance it.
|
rets = r
|
||||||
ctrl.mu.Unlock()
|
}
|
||||||
defer ctrl.mu.Lock()
|
|
||||||
if action != nil {
|
|
||||||
action()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rets
|
return rets
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctrl *Controller) Finish() {
|
func (ctrl *Controller) Finish() {
|
||||||
|
ctrl.T.Helper()
|
||||||
|
|
||||||
ctrl.mu.Lock()
|
ctrl.mu.Lock()
|
||||||
defer ctrl.mu.Unlock()
|
defer ctrl.mu.Unlock()
|
||||||
|
|
||||||
|
if ctrl.finished {
|
||||||
|
ctrl.T.Fatalf("Controller.Finish was called more than once. It has to be called exactly once.")
|
||||||
|
}
|
||||||
|
ctrl.finished = true
|
||||||
|
|
||||||
// If we're currently panicking, probably because this is a deferred call,
|
// If we're currently panicking, probably because this is a deferred call,
|
||||||
// pass through the panic.
|
// pass through the panic.
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
@ -150,18 +218,18 @@ func (ctrl *Controller) Finish() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that all remaining expected calls are satisfied.
|
// Check that all remaining expected calls are satisfied.
|
||||||
failures := false
|
failures := ctrl.expectedCalls.Failures()
|
||||||
for _, methodMap := range ctrl.expectedCalls {
|
for _, call := range failures {
|
||||||
for _, calls := range methodMap {
|
ctrl.T.Errorf("missing call(s) to %v", call)
|
||||||
for _, call := range calls {
|
}
|
||||||
if !call.satisfied() {
|
if len(failures) != 0 {
|
||||||
ctrl.t.Errorf("missing call(s) to %v", call)
|
ctrl.T.Fatalf("aborting test due to missing call(s)")
|
||||||
failures = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func callerInfo(skip int) string {
|
||||||
|
if _, file, line, ok := runtime.Caller(skip + 1); ok {
|
||||||
|
return fmt.Sprintf("%s:%d", file, line)
|
||||||
}
|
}
|
||||||
}
|
return "unknown file"
|
||||||
if failures {
|
|
||||||
ctrl.t.Fatalf("aborting test due to missing call(s)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
27
vendor/github.com/golang/mock/gomock/matchers.go
generated
vendored
27
vendor/github.com/golang/mock/gomock/matchers.go
generated
vendored
@ -22,7 +22,7 @@ import (
|
|||||||
// A Matcher is a representation of a class of values.
|
// A Matcher is a representation of a class of values.
|
||||||
// It is used to represent the valid or expected arguments to a mocked method.
|
// It is used to represent the valid or expected arguments to a mocked method.
|
||||||
type Matcher interface {
|
type Matcher interface {
|
||||||
// Matches returns whether y is a match.
|
// Matches returns whether x is a match.
|
||||||
Matches(x interface{}) bool
|
Matches(x interface{}) bool
|
||||||
|
|
||||||
// String describes what the matcher matches.
|
// String describes what the matcher matches.
|
||||||
@ -85,6 +85,18 @@ func (n notMatcher) String() string {
|
|||||||
return "not(" + n.m.String() + ")"
|
return "not(" + n.m.String() + ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type assignableToTypeOfMatcher struct {
|
||||||
|
targetType reflect.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m assignableToTypeOfMatcher) Matches(x interface{}) bool {
|
||||||
|
return reflect.TypeOf(x).AssignableTo(m.targetType)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m assignableToTypeOfMatcher) String() string {
|
||||||
|
return "is assignable to " + m.targetType.Name()
|
||||||
|
}
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
func Any() Matcher { return anyMatcher{} }
|
func Any() Matcher { return anyMatcher{} }
|
||||||
func Eq(x interface{}) Matcher { return eqMatcher{x} }
|
func Eq(x interface{}) Matcher { return eqMatcher{x} }
|
||||||
@ -95,3 +107,16 @@ func Not(x interface{}) Matcher {
|
|||||||
}
|
}
|
||||||
return notMatcher{Eq(x)}
|
return notMatcher{Eq(x)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AssignableToTypeOf is a Matcher that matches if the parameter to the mock
|
||||||
|
// function is assignable to the type of the parameter to this function.
|
||||||
|
//
|
||||||
|
// Example usage:
|
||||||
|
//
|
||||||
|
// dbMock.EXPECT().
|
||||||
|
// Insert(gomock.AssignableToTypeOf(&EmployeeRecord{})).
|
||||||
|
// Return(errors.New("DB error"))
|
||||||
|
//
|
||||||
|
func AssignableToTypeOf(x interface{}) Matcher {
|
||||||
|
return assignableToTypeOfMatcher{reflect.TypeOf(x)}
|
||||||
|
}
|
||||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -397,7 +397,7 @@ github.com/gogo/protobuf/vanity
|
|||||||
github.com/gogo/protobuf/vanity/command
|
github.com/gogo/protobuf/vanity/command
|
||||||
# github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903 => github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903
|
# github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903 => github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903
|
||||||
github.com/golang/groupcache/lru
|
github.com/golang/groupcache/lru
|
||||||
# github.com/golang/mock v0.0.0-20160127222235-bd3c8e81be01 => github.com/golang/mock v0.0.0-20160127222235-bd3c8e81be01
|
# github.com/golang/mock v1.2.0 => github.com/golang/mock v1.2.0
|
||||||
github.com/golang/mock/gomock
|
github.com/golang/mock/gomock
|
||||||
# github.com/golang/protobuf v1.2.0 => github.com/golang/protobuf v1.2.0
|
# github.com/golang/protobuf v1.2.0 => github.com/golang/protobuf v1.2.0
|
||||||
github.com/golang/protobuf/jsonpb
|
github.com/golang/protobuf/jsonpb
|
||||||
|
Loading…
Reference in New Issue
Block a user