From 8cbc5dc03f9c3012c58d2ca443997a85296a4ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=BD=87?= Date: Fri, 17 Jan 2020 22:54:49 +0800 Subject: [PATCH] Bump golang/mock version to v1.3.1 --- go.mod | 4 +- go.sum | 4 +- .../src/k8s.io/legacy-cloud-providers/go.mod | 2 +- .../src/k8s.io/legacy-cloud-providers/go.sum | 2 + .../golang/mock/gomock/controller.go | 43 ++++++++++++++++--- .../github.com/golang/mock/gomock/matchers.go | 33 +++++++++++--- vendor/modules.txt | 2 +- 7 files changed, 70 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 818f6a62534..ecbb261a547 100644 --- a/go.mod +++ b/go.mod @@ -62,7 +62,7 @@ require ( github.com/godbus/dbus v0.0.0-20181101234600-2ff6f7ffd60f // indirect github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903 - github.com/golang/mock v1.2.0 + github.com/golang/mock v1.3.1 github.com/google/cadvisor v0.35.0 github.com/google/go-cmp v0.3.0 github.com/google/gofuzz v1.0.0 @@ -297,7 +297,7 @@ replace ( github.com/golang/freetype => github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 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/mock => github.com/golang/mock v1.2.0 + github.com/golang/mock => github.com/golang/mock v1.3.1 github.com/golang/protobuf => github.com/golang/protobuf v1.3.2 github.com/golangci/check => github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 github.com/golangci/dupl => github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a diff --git a/go.sum b/go.sum index 74fa6e99f25..38fb4036e44 100644 --- a/go.sum +++ b/go.sum @@ -215,8 +215,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/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/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2/go.mod h1:k9Qvh+8juN+UKMCS/3jFtGICgW8O96FVaZsaxdzDkR4= diff --git a/staging/src/k8s.io/legacy-cloud-providers/go.mod b/staging/src/k8s.io/legacy-cloud-providers/go.mod index 631dbe985dd..6fb3a8b5da4 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/go.mod +++ b/staging/src/k8s.io/legacy-cloud-providers/go.mod @@ -15,7 +15,7 @@ require ( github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534 github.com/aws/aws-sdk-go v1.16.26 github.com/dnaeon/go-vcr v1.0.1 // indirect - github.com/golang/mock v1.2.0 + github.com/golang/mock v1.3.1 github.com/gophercloud/gophercloud v0.1.0 github.com/mitchellh/mapstructure v1.1.2 github.com/rubiojr/go-vhd v0.0.0-20160810183302-0bfd3b39853c diff --git a/staging/src/k8s.io/legacy-cloud-providers/go.sum b/staging/src/k8s.io/legacy-cloud-providers/go.sum index 542114859da..e2edb21cf4f 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/go.sum +++ b/staging/src/k8s.io/legacy-cloud-providers/go.sum @@ -100,6 +100,8 @@ github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4er github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= diff --git a/vendor/github.com/golang/mock/gomock/controller.go b/vendor/github.com/golang/mock/gomock/controller.go index 6fde25f5087..0651c91e444 100644 --- a/vendor/github.com/golang/mock/gomock/controller.go +++ b/vendor/github.com/golang/mock/gomock/controller.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// GoMock - a mock framework for Go. +// Package gomock is a mock framework for Go. // // Standard usage: // (1) Define an interface that you wish to mock. @@ -63,8 +63,8 @@ import ( "sync" ) -// A TestReporter is something that can be used to report test failures. -// It is satisfied by the standard library's *testing.T. +// A TestReporter is something that can be used to report test failures. It +// is satisfied by the standard library's *testing.T. type TestReporter interface { Errorf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) @@ -77,14 +77,35 @@ type TestHelper interface { Helper() } -// 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. +// 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. +// +// func TestFoo(t *testing.T) { +// ctrl := gomock.NewController(st) +// defer ctrl.Finish() +// // .. +// } +// +// func TestBar(t *testing.T) { +// t.Run("Sub-Test-1", st) { +// ctrl := gomock.NewController(st) +// defer ctrl.Finish() +// // .. +// }) +// t.Run("Sub-Test-2", st) { +// ctrl := gomock.NewController(st) +// defer ctrl.Finish() +// // .. +// }) +// }) 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 + // If the TestReporter does not implement a TestHelper it will be wrapped // with a nopTestHelper. T TestHelper mu sync.Mutex @@ -92,6 +113,8 @@ type Controller struct { finished bool } +// NewController returns a new Controller. It is the preferred way to create a +// Controller. func NewController(t TestReporter) *Controller { h, ok := t.(TestHelper) if !ok { @@ -135,6 +158,7 @@ type nopTestHelper struct { func (h nopTestHelper) Helper() {} +// RecordCall is called by a mock. It should not be called by user code. func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call { ctrl.T.Helper() @@ -148,6 +172,7 @@ func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ... panic("unreachable") } +// RecordCallWithMethodType is called by a mock. It should not be called by user code. func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call { ctrl.T.Helper() @@ -160,6 +185,7 @@ func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method st return call } +// Call is called by a mock. It should not be called by user code. func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} { ctrl.T.Helper() @@ -200,6 +226,9 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf return rets } +// 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. func (ctrl *Controller) Finish() { ctrl.T.Helper() diff --git a/vendor/github.com/golang/mock/gomock/matchers.go b/vendor/github.com/golang/mock/gomock/matchers.go index 189796f8656..fbff06062fa 100644 --- a/vendor/github.com/golang/mock/gomock/matchers.go +++ b/vendor/github.com/golang/mock/gomock/matchers.go @@ -98,9 +98,30 @@ func (m assignableToTypeOfMatcher) String() string { } // Constructors -func Any() Matcher { return anyMatcher{} } +// Any returns a matcher that always matches. +func Any() Matcher { return anyMatcher{} } + +// Eq returns a matcher that matches on equality. +// +// Example usage: +// Eq(5).Matches(5) // returns true +// Eq(5).Matches(4) // returns false func Eq(x interface{}) Matcher { return eqMatcher{x} } -func Nil() Matcher { return nilMatcher{} } + +// Nil returns a matcher that matches if the received value is nil. +// +// Example usage: +// var x *bytes.Buffer +// Nil().Matches(x) // returns true +// x = &bytes.Buffer{} +// Nil().Matches(x) // returns false +func Nil() Matcher { return nilMatcher{} } + +// Not reverses the results of its given child matcher. +// +// Example usage: +// Not(Eq(5)).Matches(4) // returns true +// Not(Eq(5)).Matches(5) // returns false func Not(x interface{}) Matcher { if m, ok := x.(Matcher); ok { return notMatcher{m} @@ -112,11 +133,9 @@ func Not(x interface{}) Matcher { // 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")) -// +// var s fmt.Stringer = &bytes.Buffer{} +// AssignableToTypeOf(s).Matches(time.Second) // returns true +// AssignableToTypeOf(s).Matches(99) // returns false func AssignableToTypeOf(x interface{}) Matcher { return assignableToTypeOfMatcher{reflect.TypeOf(x)} } diff --git a/vendor/modules.txt b/vendor/modules.txt index 3b8f8bc950a..1f6efb0ac3c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -328,7 +328,7 @@ github.com/gogo/protobuf/vanity 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/lru -# github.com/golang/mock v1.2.0 => github.com/golang/mock v1.2.0 +# github.com/golang/mock v1.3.1 => github.com/golang/mock v1.3.1 github.com/golang/mock/gomock # github.com/golang/protobuf v1.3.2 => github.com/golang/protobuf v1.3.2 github.com/golang/protobuf/jsonpb