From 2460602ec5f1585833f417c76528b0150b924c9b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:38:35 +0000 Subject: [PATCH] build(deps): bump go.uber.org/mock from 0.4.0 to 0.5.0 Bumps [go.uber.org/mock](https://github.com/uber/mock) from 0.4.0 to 0.5.0. - [Release notes](https://github.com/uber/mock/releases) - [Changelog](https://github.com/uber-go/mock/blob/main/CHANGELOG.md) - [Commits](https://github.com/uber/mock/compare/v0.4.0...v0.5.0) --- updated-dependencies: - dependency-name: go.uber.org/mock dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 3 +- go.sum | 4 +-- vendor/go.uber.org/mock/gomock/call.go | 12 +++---- vendor/go.uber.org/mock/gomock/controller.go | 18 +++++++--- vendor/go.uber.org/mock/gomock/matchers.go | 22 +++++++----- vendor/go.uber.org/mock/gomock/string.go | 36 ++++++++++++++++++++ vendor/modules.txt | 6 ++-- 7 files changed, 72 insertions(+), 29 deletions(-) create mode 100644 vendor/go.uber.org/mock/gomock/string.go diff --git a/go.mod b/go.mod index b499c4d61..8c505e29d 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( go.opentelemetry.io/otel/sdk/metric v1.31.0 go.uber.org/automaxprocs v1.5.3 go.uber.org/goleak v1.3.0 - go.uber.org/mock v0.4.0 + go.uber.org/mock v0.5.0 go.uber.org/multierr v1.11.0 go.uber.org/zap v1.27.0 golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df @@ -117,7 +117,6 @@ require ( golang.org/x/term v0.23.0 // indirect golang.org/x/text v0.17.0 // indirect golang.org/x/time v0.3.0 // indirect - golang.org/x/tools v0.22.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect gopkg.in/inf.v0 v0.9.1 // indirect diff --git a/go.sum b/go.sum index f685b2ac9..88431de12 100644 --- a/go.sum +++ b/go.sum @@ -396,8 +396,8 @@ go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8= go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= -go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= +go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= +go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= diff --git a/vendor/go.uber.org/mock/gomock/call.go b/vendor/go.uber.org/mock/gomock/call.go index e1ea82637..e1fe222af 100644 --- a/vendor/go.uber.org/mock/gomock/call.go +++ b/vendor/go.uber.org/mock/gomock/call.go @@ -75,8 +75,10 @@ func newCall(t TestHelper, receiver any, method string, methodType reflect.Type, } return rets }} - return &Call{t: t, receiver: receiver, method: method, methodType: methodType, - args: mArgs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions} + 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 @@ -251,11 +253,7 @@ func (c *Call) SetArg(n int, value any) *Call { c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]", n, vt, dt, c.origin) } - case reflect.Interface: - // nothing to do - case reflect.Slice: - // nothing to do - case reflect.Map: + case reflect.Interface, reflect.Slice, reflect.Map: // nothing to do default: c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice non-map type %v [%s]", diff --git a/vendor/go.uber.org/mock/gomock/controller.go b/vendor/go.uber.org/mock/gomock/controller.go index 9d17a2f0c..674c3298c 100644 --- a/vendor/go.uber.org/mock/gomock/controller.go +++ b/vendor/go.uber.org/mock/gomock/controller.go @@ -48,8 +48,7 @@ type cleanuper interface { // 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 -// goroutines. Each test should create a new Controller and invoke Finish via -// defer. +// goroutines. Each test should create a new Controller. // // func TestFoo(t *testing.T) { // ctrl := gomock.NewController(t) @@ -129,6 +128,7 @@ type cancelReporter struct { func (r *cancelReporter) Errorf(format string, args ...any) { r.t.Errorf(format, args...) } + func (r *cancelReporter) Fatalf(format string, args ...any) { defer r.cancel() r.t.Fatalf(format, args...) @@ -157,6 +157,7 @@ type nopTestHelper struct { func (h *nopTestHelper) Errorf(format string, args ...any) { h.t.Errorf(format, args...) } + func (h *nopTestHelper) Fatalf(format string, args ...any) { h.t.Fatalf(format, args...) } @@ -206,12 +207,16 @@ func (ctrl *Controller) Call(receiver any, method string, args ...any) []any { // 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) + stringArgs := make([]string, len(args)) + for i, arg := range args { + stringArgs[i] = getString(arg) + } + ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, stringArgs, origin, err) } // Two things happen here: - // * the matching call no longer needs to check prerequite calls, - // * and the prerequite calls are no longer expected, so remove them. + // * the matching call no longer needs to check prerequisite calls, + // * and the prerequisite calls are no longer expected, so remove them. preReqCalls := expected.dropPrereqs() for _, preReqCall := range preReqCalls { ctrl.expectedCalls.Remove(preReqCall) @@ -236,6 +241,9 @@ func (ctrl *Controller) Call(receiver any, method string, args ...any) []any { // Finish checks to see if all the methods that were expected to be called were called. // It is not idempotent and therefore can only be invoked once. +// +// Note: If you pass a *testing.T into [NewController], 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. diff --git a/vendor/go.uber.org/mock/gomock/matchers.go b/vendor/go.uber.org/mock/gomock/matchers.go index c17255096..d52495f39 100644 --- a/vendor/go.uber.org/mock/gomock/matchers.go +++ b/vendor/go.uber.org/mock/gomock/matchers.go @@ -98,15 +98,19 @@ func (anyMatcher) String() string { return "is anything" } -type condMatcher struct { - fn func(x any) bool +type condMatcher[T any] struct { + fn func(x T) bool } -func (c condMatcher) Matches(x any) bool { - return c.fn(x) +func (c condMatcher[T]) Matches(x any) bool { + typed, ok := x.(T) + if !ok { + return false + } + return c.fn(typed) } -func (condMatcher) String() string { +func (c condMatcher[T]) String() string { return "adheres to a custom condition" } @@ -133,7 +137,7 @@ func (e eqMatcher) Matches(x any) bool { } func (e eqMatcher) String() string { - return fmt.Sprintf("is equal to %v (%T)", e.x, e.x) + return fmt.Sprintf("is equal to %s (%T)", getString(e.x), e.x) } type nilMatcher struct{} @@ -339,9 +343,9 @@ func Any() Matcher { return anyMatcher{} } // // Example usage: // -// Cond(func(x any){return x.(int) == 1}).Matches(1) // returns true -// Cond(func(x any){return x.(int) == 2}).Matches(1) // returns false -func Cond(fn func(x any) bool) Matcher { return condMatcher{fn} } +// Cond(func(x int){return x == 1}).Matches(1) // returns true +// Cond(func(x int){return x == 2}).Matches(1) // returns false +func Cond[T any](fn func(x T) bool) Matcher { return condMatcher[T]{fn} } // AnyOf returns a composite Matcher that returns true if at least one of the // matchers returns true. diff --git a/vendor/go.uber.org/mock/gomock/string.go b/vendor/go.uber.org/mock/gomock/string.go new file mode 100644 index 000000000..ec4ca7e4d --- /dev/null +++ b/vendor/go.uber.org/mock/gomock/string.go @@ -0,0 +1,36 @@ +package gomock + +import ( + "fmt" + "reflect" +) + +// getString is a safe way to convert a value to a string for printing results +// If the value is a a mock, getString avoids calling the mocked String() method, +// which avoids potential deadlocks +func getString(x any) string { + if isGeneratedMock(x) { + return fmt.Sprintf("%T", x) + } + if s, ok := x.(fmt.Stringer); ok { + return s.String() + } + return fmt.Sprintf("%v", x) +} + +// isGeneratedMock checks if the given type has a "isgomock" field, +// indicating it is a generated mock. +func isGeneratedMock(x any) bool { + typ := reflect.TypeOf(x) + if typ == nil { + return false + } + if typ.Kind() == reflect.Ptr { + typ = typ.Elem() + } + if typ.Kind() != reflect.Struct { + return false + } + _, isgomock := typ.FieldByName("isgomock") + return isgomock +} diff --git a/vendor/modules.txt b/vendor/modules.txt index a68370306..a18986018 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -450,8 +450,8 @@ go.uber.org/automaxprocs/maxprocs ## explicit; go 1.20 go.uber.org/goleak go.uber.org/goleak/internal/stack -# go.uber.org/mock v0.4.0 -## explicit; go 1.20 +# go.uber.org/mock v0.5.0 +## explicit; go 1.22 go.uber.org/mock/gomock go.uber.org/mock/mockgen/model # go.uber.org/multierr v1.11.0 @@ -516,8 +516,6 @@ golang.org/x/text/unicode/norm # golang.org/x/time v0.3.0 ## explicit golang.org/x/time/rate -# golang.org/x/tools v0.22.0 -## explicit; go 1.19 # google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd ## explicit; go 1.21 google.golang.org/genproto/googleapis/api/httpbody