[VOL-5486] Fix deprecated versions
Change-Id: Ia8cf5de26cc045c8519da848cd4314459a331e16
Signed-off-by: Abhay Kumar <abhay.kumar@radisys.com>
diff --git a/vendor/github.com/golang/mock/gomock/call.go b/vendor/github.com/golang/mock/gomock/call.go
index 7345f65..13c9f44 100644
--- a/vendor/github.com/golang/mock/gomock/call.go
+++ b/vendor/github.com/golang/mock/gomock/call.go
@@ -50,19 +50,22 @@
t.Helper()
// TODO: check arity, types.
- margs := make([]Matcher, len(args))
+ mArgs := make([]Matcher, len(args))
for i, arg := range args {
if m, ok := arg.(Matcher); ok {
- margs[i] = m
+ 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()
+ mArgs[i] = Nil()
} else {
- margs[i] = Eq(arg)
+ mArgs[i] = Eq(arg)
}
}
+ // callerInfo's skip should be updated if the number of calls between the user's test
+ // and this line changes, i.e. this code is wrapped in another anonymous function.
+ // 0 is us, 1 is RecordCallWithMethodType(), 2 is the generated recorder, and 3 is the user's test.
origin := callerInfo(3)
actions := []func([]interface{}) []interface{}{func([]interface{}) []interface{} {
// Synthesize the zero value for each of the return args' types.
@@ -73,7 +76,7 @@
return rets
}}
return &Call{t: t, receiver: receiver, method: method, methodType: methodType,
- args: margs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions}
+ args: mArgs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions}
}
// AnyTimes allows the expectation to be called 0 or more times
@@ -110,19 +113,25 @@
v := reflect.ValueOf(f)
c.addAction(func(args []interface{}) []interface{} {
- vargs := make([]reflect.Value, len(args))
+ c.t.Helper()
+ vArgs := make([]reflect.Value, len(args))
ft := v.Type()
+ if c.methodType.NumIn() != ft.NumIn() {
+ c.t.Fatalf("wrong number of arguments in DoAndReturn func for %T.%v: got %d, want %d [%s]",
+ c.receiver, c.method, ft.NumIn(), c.methodType.NumIn(), c.origin)
+ return nil
+ }
for i := 0; i < len(args); i++ {
if args[i] != nil {
- vargs[i] = reflect.ValueOf(args[i])
+ vArgs[i] = reflect.ValueOf(args[i])
} else {
// Use the zero value for the arg.
- vargs[i] = reflect.Zero(ft.In(i))
+ vArgs[i] = reflect.Zero(ft.In(i))
}
}
- vrets := v.Call(vargs)
- rets := make([]interface{}, len(vrets))
- for i, ret := range vrets {
+ vRets := v.Call(vArgs)
+ rets := make([]interface{}, len(vRets))
+ for i, ret := range vRets {
rets[i] = ret.Interface()
}
return rets
@@ -139,17 +148,23 @@
v := reflect.ValueOf(f)
c.addAction(func(args []interface{}) []interface{} {
- vargs := make([]reflect.Value, len(args))
+ c.t.Helper()
+ if c.methodType.NumIn() != v.Type().NumIn() {
+ c.t.Fatalf("wrong number of arguments in Do func for %T.%v: got %d, want %d [%s]",
+ c.receiver, c.method, v.Type().NumIn(), c.methodType.NumIn(), c.origin)
+ return nil
+ }
+ 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])
+ vArgs[i] = reflect.ValueOf(args[i])
} else {
// Use the zero value for the arg.
- vargs[i] = reflect.Zero(ft.In(i))
+ vArgs[i] = reflect.Zero(ft.In(i))
}
}
- v.Call(vargs)
+ v.Call(vArgs)
return nil
})
return c
@@ -301,14 +316,9 @@
for i, m := range c.args {
if !m.Matches(args[i]) {
- got := fmt.Sprintf("%v", args[i])
- if gs, ok := m.(GotFormatter); ok {
- got = gs.Got(args[i])
- }
-
return fmt.Errorf(
"expected call at %s doesn't match the argument at index %d.\nGot: %v\nWant: %v",
- c.origin, i, got, m,
+ c.origin, i, formatGottenArg(m, args[i]), m,
)
}
}
@@ -331,7 +341,7 @@
// 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)
+ c.origin, strconv.Itoa(i), formatGottenArg(m, args[i]), m)
}
continue
}
@@ -355,12 +365,12 @@
// 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)
+ 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))
+ vArgs = reflect.Append(vArgs, reflect.ValueOf(arg))
}
- if m.Matches(vargs.Interface()) {
+ 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())
@@ -373,16 +383,16 @@
// 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])
+ return fmt.Errorf("expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v",
+ c.origin, strconv.Itoa(i), formatGottenArg(m, args[i:]), c.args[i])
}
}
// Check that all prerequisite calls have been satisfied.
for _, preReqCall := range c.preReqs {
if !preReqCall.satisfied() {
- return fmt.Errorf("Expected call at %s doesn't have a prerequisite call satisfied:\n%v\nshould be called before:\n%v",
+ 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)
}
}
@@ -425,3 +435,11 @@
func (c *Call) addAction(action func([]interface{}) []interface{}) {
c.actions = append(c.actions, action)
}
+
+func formatGottenArg(m Matcher, arg interface{}) string {
+ got := fmt.Sprintf("%v (%T)", arg, arg)
+ if gs, ok := m.(GotFormatter); ok {
+ got = gs.Got(arg)
+ }
+ return got
+}