[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
+}
diff --git a/vendor/github.com/golang/mock/gomock/callset.go b/vendor/github.com/golang/mock/gomock/callset.go
index b046b52..49dba78 100644
--- a/vendor/github.com/golang/mock/gomock/callset.go
+++ b/vendor/github.com/golang/mock/gomock/callset.go
@@ -16,6 +16,7 @@
import (
"bytes"
+ "errors"
"fmt"
)
@@ -84,14 +85,18 @@
for _, call := range exhausted {
if err := call.matches(args); err != nil {
_, _ = fmt.Fprintf(&callsErrors, "\n%v", err)
+ continue
}
+ _, _ = fmt.Fprintf(
+ &callsErrors, "all expected calls for method %q have been exhausted", method,
+ )
}
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())
+ return nil, errors.New(callsErrors.String())
}
// Failures returns the calls that are not satisfied.
diff --git a/vendor/github.com/golang/mock/gomock/controller.go b/vendor/github.com/golang/mock/gomock/controller.go
index d7c3c65..f054200 100644
--- a/vendor/github.com/golang/mock/gomock/controller.go
+++ b/vendor/github.com/golang/mock/gomock/controller.go
@@ -50,9 +50,6 @@
// mockObj.EXPECT().SomeMethod(2, "second"),
// mockObj.EXPECT().SomeMethod(3, "third"),
// )
-//
-// TODO:
-// - Handle different argument/return types (e.g. ..., chan, map, interface).
package gomock
import (
@@ -77,6 +74,15 @@
Helper()
}
+// cleanuper is used to check if TestHelper also has the `Cleanup` method. A
+// common pattern is to pass in a `*testing.T` to
+// `NewController(t TestReporter)`. In Go 1.14+, `*testing.T` has a cleanup
+// method. This can be utilized to call `Finish()` so the caller of this library
+// does not have to.
+type cleanuper interface {
+ Cleanup(func())
+}
+
// 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 is safe to call Controller's methods from multiple
@@ -115,29 +121,43 @@
// NewController returns a new Controller. It is the preferred way to create a
// Controller.
+//
+// New in go1.14+, if you are passing a *testing.T into this function you no
+// longer need to call ctrl.Finish() in your test methods.
func NewController(t TestReporter) *Controller {
h, ok := t.(TestHelper)
if !ok {
- h = nopTestHelper{t}
+ h = &nopTestHelper{t}
}
-
- return &Controller{
+ ctrl := &Controller{
T: h,
expectedCalls: newCallSet(),
}
+ if c, ok := isCleanuper(ctrl.T); ok {
+ c.Cleanup(func() {
+ ctrl.T.Helper()
+ ctrl.finish(true, nil)
+ })
+ }
+
+ return ctrl
}
type cancelReporter struct {
- TestHelper
+ t TestHelper
cancel func()
}
func (r *cancelReporter) Errorf(format string, args ...interface{}) {
- r.TestHelper.Errorf(format, args...)
+ r.t.Errorf(format, args...)
}
func (r *cancelReporter) Fatalf(format string, args ...interface{}) {
defer r.cancel()
- r.TestHelper.Fatalf(format, args...)
+ r.t.Fatalf(format, args...)
+}
+
+func (r *cancelReporter) Helper() {
+ r.t.Helper()
}
// WithContext returns a new Controller and a Context, which is cancelled on any
@@ -145,15 +165,22 @@
func WithContext(ctx context.Context, t TestReporter) (*Controller, context.Context) {
h, ok := t.(TestHelper)
if !ok {
- h = nopTestHelper{t}
+ h = &nopTestHelper{t: t}
}
ctx, cancel := context.WithCancel(ctx)
- return NewController(&cancelReporter{h, cancel}), ctx
+ return NewController(&cancelReporter{t: h, cancel: cancel}), ctx
}
type nopTestHelper struct {
- TestReporter
+ t TestReporter
+}
+
+func (h *nopTestHelper) Errorf(format string, args ...interface{}) {
+ h.t.Errorf(format, args...)
+}
+func (h *nopTestHelper) Fatalf(format string, args ...interface{}) {
+ h.t.Fatalf(format, args...)
}
func (h nopTestHelper) Helper() {}
@@ -197,7 +224,10 @@
expected, err := ctrl.expectedCalls.FindMatch(receiver, method, args)
if err != nil {
- origin := callerInfo(2)
+ // 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 controller.Call(), 2 is the generated mock, and 3 is the user's test.
+ origin := callerInfo(3)
ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, args, origin, err)
}
@@ -229,21 +259,33 @@
// Finish checks to see if all the methods that were expected to be called
// were called. It should be invoked for each Controller. It is not idempotent
// and therefore can only be invoked once.
+//
+// New in go1.14+, if you are passing a *testing.T into NewController function you no
+// longer need to call ctrl.Finish() in your test methods.
func (ctrl *Controller) Finish() {
+ // If we're currently panicking, probably because this is a deferred call.
+ // This must be recovered in the deferred function.
+ err := recover()
+ ctrl.finish(false, err)
+}
+
+func (ctrl *Controller) finish(cleanup bool, panicErr interface{}) {
ctrl.T.Helper()
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
if ctrl.finished {
- ctrl.T.Fatalf("Controller.Finish was called more than once. It has to be called exactly once.")
+ if _, ok := isCleanuper(ctrl.T); !ok {
+ ctrl.T.Fatalf("Controller.Finish was called more than once. It has to be called exactly once.")
+ }
+ return
}
ctrl.finished = true
- // If we're currently panicking, probably because this is a deferred call,
- // pass through the panic.
- if err := recover(); err != nil {
- panic(err)
+ // Short-circuit, pass through the panic.
+ if panicErr != nil {
+ panic(panicErr)
}
// Check that all remaining expected calls are satisfied.
@@ -252,13 +294,43 @@
ctrl.T.Errorf("missing call(s) to %v", call)
}
if len(failures) != 0 {
- ctrl.T.Fatalf("aborting test due to missing call(s)")
+ if !cleanup {
+ ctrl.T.Fatalf("aborting test due to missing call(s)")
+ return
+ }
+ ctrl.T.Errorf("aborting test due to missing call(s)")
}
}
+// callerInfo returns the file:line of the call site. skip is the number
+// of stack frames to skip when reporting. 0 is callerInfo's call site.
func callerInfo(skip int) string {
if _, file, line, ok := runtime.Caller(skip + 1); ok {
return fmt.Sprintf("%s:%d", file, line)
}
return "unknown file"
}
+
+// isCleanuper checks it if t's base TestReporter has a Cleanup method.
+func isCleanuper(t TestReporter) (cleanuper, bool) {
+ tr := unwrapTestReporter(t)
+ c, ok := tr.(cleanuper)
+ return c, ok
+}
+
+// unwrapTestReporter unwraps TestReporter to the base implementation.
+func unwrapTestReporter(t TestReporter) TestReporter {
+ tr := t
+ switch nt := t.(type) {
+ case *cancelReporter:
+ tr = nt.t
+ if h, check := tr.(*nopTestHelper); check {
+ tr = h.t
+ }
+ case *nopTestHelper:
+ tr = nt.t
+ default:
+ // not wrapped
+ }
+ return tr
+}
diff --git a/vendor/github.com/golang/mock/gomock/matchers.go b/vendor/github.com/golang/mock/gomock/matchers.go
index 7bfc07b..2822fb2 100644
--- a/vendor/github.com/golang/mock/gomock/matchers.go
+++ b/vendor/github.com/golang/mock/gomock/matchers.go
@@ -102,11 +102,25 @@
}
func (e eqMatcher) Matches(x interface{}) bool {
- return reflect.DeepEqual(e.x, x)
+ // In case, some value is nil
+ if e.x == nil || x == nil {
+ return reflect.DeepEqual(e.x, x)
+ }
+
+ // Check if types assignable and convert them to common type
+ x1Val := reflect.ValueOf(e.x)
+ x2Val := reflect.ValueOf(x)
+
+ if x1Val.Type().AssignableTo(x2Val.Type()) {
+ x1ValConverted := x1Val.Convert(x2Val.Type())
+ return reflect.DeepEqual(x1ValConverted.Interface(), x2Val.Interface())
+ }
+
+ return false
}
func (e eqMatcher) String() string {
- return fmt.Sprintf("is equal to %v", e.x)
+ return fmt.Sprintf("is equal to %v (%T)", e.x, e.x)
}
type nilMatcher struct{}
@@ -139,7 +153,6 @@
}
func (n notMatcher) String() string {
- // TODO: Improve this if we add a NotString method to the Matcher interface.
return "not(" + n.m.String() + ")"
}
@@ -194,6 +207,70 @@
return fmt.Sprintf("has length %d", m.i)
}
+type inAnyOrderMatcher struct {
+ x interface{}
+}
+
+func (m inAnyOrderMatcher) Matches(x interface{}) bool {
+ given, ok := m.prepareValue(x)
+ if !ok {
+ return false
+ }
+ wanted, ok := m.prepareValue(m.x)
+ if !ok {
+ return false
+ }
+
+ if given.Len() != wanted.Len() {
+ return false
+ }
+
+ usedFromGiven := make([]bool, given.Len())
+ foundFromWanted := make([]bool, wanted.Len())
+ for i := 0; i < wanted.Len(); i++ {
+ wantedMatcher := Eq(wanted.Index(i).Interface())
+ for j := 0; j < given.Len(); j++ {
+ if usedFromGiven[j] {
+ continue
+ }
+ if wantedMatcher.Matches(given.Index(j).Interface()) {
+ foundFromWanted[i] = true
+ usedFromGiven[j] = true
+ break
+ }
+ }
+ }
+
+ missingFromWanted := 0
+ for _, found := range foundFromWanted {
+ if !found {
+ missingFromWanted++
+ }
+ }
+ extraInGiven := 0
+ for _, used := range usedFromGiven {
+ if !used {
+ extraInGiven++
+ }
+ }
+
+ return extraInGiven == 0 && missingFromWanted == 0
+}
+
+func (m inAnyOrderMatcher) prepareValue(x interface{}) (reflect.Value, bool) {
+ xValue := reflect.ValueOf(x)
+ switch xValue.Kind() {
+ case reflect.Slice, reflect.Array:
+ return xValue, true
+ default:
+ return reflect.Value{}, false
+ }
+}
+
+func (m inAnyOrderMatcher) String() string {
+ return fmt.Sprintf("has the same elements as %v", m.x)
+}
+
// Constructors
// All returns a composite Matcher that returns true if and only all of the
@@ -245,7 +322,7 @@
// AssignableToTypeOf(s).Matches(time.Second) // returns true
// AssignableToTypeOf(s).Matches(99) // returns false
//
-// var ctx = reflect.TypeOf((*context.Context)).Elem()
+// var ctx = reflect.TypeOf((*context.Context)(nil)).Elem()
// AssignableToTypeOf(ctx).Matches(context.Background()) // returns true
func AssignableToTypeOf(x interface{}) Matcher {
if xt, ok := x.(reflect.Type); ok {
@@ -253,3 +330,12 @@
}
return assignableToTypeOfMatcher{reflect.TypeOf(x)}
}
+
+// InAnyOrder is a Matcher that returns true for collections of the same elements ignoring the order.
+//
+// Example usage:
+// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 3, 2}) // returns true
+// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 2}) // returns false
+func InAnyOrder(x interface{}) Matcher {
+ return inAnyOrderMatcher{x}
+}