From de58b3bf750b3830cf1aa9de8aca9c2083ab9b4a Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Fri, 12 Jan 2024 16:30:36 +0300 Subject: [PATCH] switch one mock to typed --- .github/workflows/check-codegen.yml | 2 +- go.mod | 2 +- go.sum | 2 + .../batched_stream_reader_mock_test.go | 15 +-- .../message_content_pool_test.go | 2 +- .../pool_interface_mock_test.go | 15 +-- .../raw_topic_reader_stream_mock_test.go | 9 +- .../topic/topicreaderinternal/reader_test.go | 2 +- .../stream_reader_impl_test.go | 2 +- .../stream_reconnector_test.go | 2 +- .../raw_topic_writer_stream_mock_test.go | 9 +- .../writer_reconnector_test.go | 2 +- .../writer_stream_interface_mock_test.go | 91 +++++++++++++++++-- .../topic/topicwriterinternal/writer_test.go | 2 +- 14 files changed, 123 insertions(+), 34 deletions(-) diff --git a/.github/workflows/check-codegen.yml b/.github/workflows/check-codegen.yml index df264bfb7..a4be45c6f 100644 --- a/.github/workflows/check-codegen.yml +++ b/.github/workflows/check-codegen.yml @@ -32,7 +32,7 @@ jobs: - name: Build run: | go install ./internal/cmd/gtrace - go install github.com/golang/mock/mockgen@v1.6.0 + go install go.uber.org/mock/mockgen@892b665398ecece7c7a900d2a2f2fa3dac07e4c4 - name: Clean and re-generate *_gtrace.go files run: | diff --git a/go.mod b/go.mod index 809750187..db13a5944 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( // requires for tests only require ( - github.com/golang/mock v1.6.0 + go.uber.org/mock v0.3.1-0.20231011042131-892b665398ec // indirect github.com/rekby/fixenv v0.3.2 github.com/stretchr/testify v1.7.1 ) diff --git a/go.sum b/go.sum index 7720358a3..f58f0f4f3 100644 --- a/go.sum +++ b/go.sum @@ -70,6 +70,8 @@ github.com/ydb-platform/ydb-go-genproto v0.0.0-20231215113745-46f6d30f974a h1:9w github.com/ydb-platform/ydb-go-genproto v0.0.0-20231215113745-46f6d30f974a/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +go.uber.org/mock v0.3.1-0.20231011042131-892b665398ec h1:aB0WVMCyiVcqL1yMRLM4htiFlMvgdOml97GYnw9su5Q= +go.uber.org/mock v0.3.1-0.20231011042131-892b665398ec/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/internal/topic/topicreaderinternal/batched_stream_reader_mock_test.go b/internal/topic/topicreaderinternal/batched_stream_reader_mock_test.go index 89fea5b00..a29699ff5 100644 --- a/internal/topic/topicreaderinternal/batched_stream_reader_mock_test.go +++ b/internal/topic/topicreaderinternal/batched_stream_reader_mock_test.go @@ -1,13 +1,16 @@ // Code generated by MockGen. DO NOT EDIT. // Source: batched_stream_reader_interface.go - +// +// Generated by this command: +// +// mockgen -source batched_stream_reader_interface.go -destination batched_stream_reader_mock_test.go -package topicreaderinternal -write_package_comment=false package topicreaderinternal import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockbatchedStreamReader is a mock of batchedStreamReader interface. @@ -42,7 +45,7 @@ func (m *MockbatchedStreamReader) CloseWithError(ctx context.Context, err error) } // CloseWithError indicates an expected call of CloseWithError. -func (mr *MockbatchedStreamReaderMockRecorder) CloseWithError(ctx, err interface{}) *gomock.Call { +func (mr *MockbatchedStreamReaderMockRecorder) CloseWithError(ctx, err any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloseWithError", reflect.TypeOf((*MockbatchedStreamReader)(nil).CloseWithError), ctx, err) } @@ -56,7 +59,7 @@ func (m *MockbatchedStreamReader) Commit(ctx context.Context, commitRange commit } // Commit indicates an expected call of Commit. -func (mr *MockbatchedStreamReaderMockRecorder) Commit(ctx, commitRange interface{}) *gomock.Call { +func (mr *MockbatchedStreamReaderMockRecorder) Commit(ctx, commitRange any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Commit", reflect.TypeOf((*MockbatchedStreamReader)(nil).Commit), ctx, commitRange) } @@ -71,7 +74,7 @@ func (m *MockbatchedStreamReader) ReadMessageBatch(ctx context.Context, opts Rea } // ReadMessageBatch indicates an expected call of ReadMessageBatch. -func (mr *MockbatchedStreamReaderMockRecorder) ReadMessageBatch(ctx, opts interface{}) *gomock.Call { +func (mr *MockbatchedStreamReaderMockRecorder) ReadMessageBatch(ctx, opts any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadMessageBatch", reflect.TypeOf((*MockbatchedStreamReader)(nil).ReadMessageBatch), ctx, opts) } @@ -85,7 +88,7 @@ func (m *MockbatchedStreamReader) WaitInit(ctx context.Context) error { } // WaitInit indicates an expected call of WaitInit. -func (mr *MockbatchedStreamReaderMockRecorder) WaitInit(ctx interface{}) *gomock.Call { +func (mr *MockbatchedStreamReaderMockRecorder) WaitInit(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WaitInit", reflect.TypeOf((*MockbatchedStreamReader)(nil).WaitInit), ctx) } diff --git a/internal/topic/topicreaderinternal/message_content_pool_test.go b/internal/topic/topicreaderinternal/message_content_pool_test.go index c60b4fe5e..63b13df97 100644 --- a/internal/topic/topicreaderinternal/message_content_pool_test.go +++ b/internal/topic/topicreaderinternal/message_content_pool_test.go @@ -6,8 +6,8 @@ import ( "io" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" ) diff --git a/internal/topic/topicreaderinternal/pool_interface_mock_test.go b/internal/topic/topicreaderinternal/pool_interface_mock_test.go index a1f84aa81..007ee441b 100644 --- a/internal/topic/topicreaderinternal/pool_interface_mock_test.go +++ b/internal/topic/topicreaderinternal/pool_interface_mock_test.go @@ -1,12 +1,15 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/ydb-platform/ydb-go-sdk/v3/internal/topic/topicreaderinternal (interfaces: Pool) - +// +// Generated by this command: +// +// mockgen -destination=pool_interface_mock_test.go -write_package_comment=false -package=topicreaderinternal github.com/ydb-platform/ydb-go-sdk/v3/internal/topic/topicreaderinternal Pool package topicreaderinternal import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockPool is a mock of Pool interface. @@ -33,10 +36,10 @@ func (m *MockPool) EXPECT() *MockPoolMockRecorder { } // Get mocks base method. -func (m *MockPool) Get() interface{} { +func (m *MockPool) Get() any { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get") - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(any) return ret0 } @@ -47,13 +50,13 @@ func (mr *MockPoolMockRecorder) Get() *gomock.Call { } // Put mocks base method. -func (m *MockPool) Put(arg0 interface{}) { +func (m *MockPool) Put(arg0 any) { m.ctrl.T.Helper() m.ctrl.Call(m, "Put", arg0) } // Put indicates an expected call of Put. -func (mr *MockPoolMockRecorder) Put(arg0 interface{}) *gomock.Call { +func (mr *MockPoolMockRecorder) Put(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockPool)(nil).Put), arg0) } diff --git a/internal/topic/topicreaderinternal/raw_topic_reader_stream_mock_test.go b/internal/topic/topicreaderinternal/raw_topic_reader_stream_mock_test.go index 70bc7bb47..35b83152f 100644 --- a/internal/topic/topicreaderinternal/raw_topic_reader_stream_mock_test.go +++ b/internal/topic/topicreaderinternal/raw_topic_reader_stream_mock_test.go @@ -1,13 +1,16 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/ydb-platform/ydb-go-sdk/v3/internal/topic/topicreaderinternal (interfaces: RawTopicReaderStream) - +// +// Generated by this command: +// +// mockgen -destination raw_topic_reader_stream_mock_test.go -package topicreaderinternal -write_package_comment=false . RawTopicReaderStream package topicreaderinternal import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" rawtopicreader "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopicreader" + gomock "go.uber.org/mock/gomock" ) // MockRawTopicReaderStream is a mock of RawTopicReaderStream interface. @@ -71,7 +74,7 @@ func (m *MockRawTopicReaderStream) Send(arg0 rawtopicreader.ClientMessage) error } // Send indicates an expected call of Send. -func (mr *MockRawTopicReaderStreamMockRecorder) Send(arg0 interface{}) *gomock.Call { +func (mr *MockRawTopicReaderStreamMockRecorder) Send(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockRawTopicReaderStream)(nil).Send), arg0) } diff --git a/internal/topic/topicreaderinternal/reader_test.go b/internal/topic/topicreaderinternal/reader_test.go index 58191a14a..18679e758 100644 --- a/internal/topic/topicreaderinternal/reader_test.go +++ b/internal/topic/topicreaderinternal/reader_test.go @@ -6,9 +6,9 @@ import ( "runtime" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "github.com/ydb-platform/ydb-go-sdk/v3/internal/empty" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext" diff --git a/internal/topic/topicreaderinternal/stream_reader_impl_test.go b/internal/topic/topicreaderinternal/stream_reader_impl_test.go index 9f76fae9a..4cf05a21c 100644 --- a/internal/topic/topicreaderinternal/stream_reader_impl_test.go +++ b/internal/topic/topicreaderinternal/stream_reader_impl_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "github.com/ydb-platform/ydb-go-sdk/v3/internal/empty" "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopiccommon" diff --git a/internal/topic/topicreaderinternal/stream_reconnector_test.go b/internal/topic/topicreaderinternal/stream_reconnector_test.go index f9a7fb6de..57b0f00dc 100644 --- a/internal/topic/topicreaderinternal/stream_reconnector_test.go +++ b/internal/topic/topicreaderinternal/stream_reconnector_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "github.com/ydb-platform/ydb-go-sdk/v3/internal/background" "github.com/ydb-platform/ydb-go-sdk/v3/internal/empty" diff --git a/internal/topic/topicwriterinternal/raw_topic_writer_stream_mock_test.go b/internal/topic/topicwriterinternal/raw_topic_writer_stream_mock_test.go index cedc4b9c8..bad3cd981 100644 --- a/internal/topic/topicwriterinternal/raw_topic_writer_stream_mock_test.go +++ b/internal/topic/topicwriterinternal/raw_topic_writer_stream_mock_test.go @@ -1,13 +1,16 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/ydb-platform/ydb-go-sdk/v3/internal/topic/topicwriterinternal (interfaces: RawTopicWriterStream) - +// +// Generated by this command: +// +// mockgen -destination raw_topic_writer_stream_mock_test.go -package topicwriterinternal -write_package_comment=false github.com/ydb-platform/ydb-go-sdk/v3/internal/topic/topicwriterinternal RawTopicWriterStream package topicwriterinternal import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" rawtopicwriter "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopicwriter" + gomock "go.uber.org/mock/gomock" ) // MockRawTopicWriterStream is a mock of RawTopicWriterStream interface. @@ -71,7 +74,7 @@ func (m *MockRawTopicWriterStream) Send(arg0 rawtopicwriter.ClientMessage) error } // Send indicates an expected call of Send. -func (mr *MockRawTopicWriterStreamMockRecorder) Send(arg0 interface{}) *gomock.Call { +func (mr *MockRawTopicWriterStreamMockRecorder) Send(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockRawTopicWriterStream)(nil).Send), arg0) } diff --git a/internal/topic/topicwriterinternal/writer_reconnector_test.go b/internal/topic/topicwriterinternal/writer_reconnector_test.go index a029154c7..dbfeedec2 100644 --- a/internal/topic/topicwriterinternal/writer_reconnector_test.go +++ b/internal/topic/topicwriterinternal/writer_reconnector_test.go @@ -13,8 +13,8 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "github.com/ydb-platform/ydb-go-sdk/v3/internal/empty" "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopiccommon" diff --git a/internal/topic/topicwriterinternal/writer_stream_interface_mock_test.go b/internal/topic/topicwriterinternal/writer_stream_interface_mock_test.go index a663d3409..1ce0f68f9 100644 --- a/internal/topic/topicwriterinternal/writer_stream_interface_mock_test.go +++ b/internal/topic/topicwriterinternal/writer_stream_interface_mock_test.go @@ -1,13 +1,16 @@ // Code generated by MockGen. DO NOT EDIT. // Source: writer_stream_interface.go - +// +// Generated by this command: +// +// mockgen -source writer_stream_interface.go -destination writer_stream_interface_mock_test.go -package topicwriterinternal -write_package_comment=false -typed package topicwriterinternal import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockStreamWriter is a mock of StreamWriter interface. @@ -42,9 +45,33 @@ func (m *MockStreamWriter) Close(ctx context.Context) error { } // Close indicates an expected call of Close. -func (mr *MockStreamWriterMockRecorder) Close(ctx interface{}) *gomock.Call { +func (mr *MockStreamWriterMockRecorder) Close(ctx any) *StreamWriterCloseCall { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockStreamWriter)(nil).Close), ctx) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockStreamWriter)(nil).Close), ctx) + return &StreamWriterCloseCall{Call: call} +} + +// StreamWriterCloseCall wrap *gomock.Call +type StreamWriterCloseCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *StreamWriterCloseCall) Return(arg0 error) *StreamWriterCloseCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *StreamWriterCloseCall) Do(f func(context.Context) error) *StreamWriterCloseCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *StreamWriterCloseCall) DoAndReturn(f func(context.Context) error) *StreamWriterCloseCall { + c.Call = c.Call.DoAndReturn(f) + return c } // WaitInit mocks base method. @@ -57,9 +84,33 @@ func (m *MockStreamWriter) WaitInit(ctx context.Context) (InitialInfo, error) { } // WaitInit indicates an expected call of WaitInit. -func (mr *MockStreamWriterMockRecorder) WaitInit(ctx interface{}) *gomock.Call { +func (mr *MockStreamWriterMockRecorder) WaitInit(ctx any) *StreamWriterWaitInitCall { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WaitInit", reflect.TypeOf((*MockStreamWriter)(nil).WaitInit), ctx) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WaitInit", reflect.TypeOf((*MockStreamWriter)(nil).WaitInit), ctx) + return &StreamWriterWaitInitCall{Call: call} +} + +// StreamWriterWaitInitCall wrap *gomock.Call +type StreamWriterWaitInitCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *StreamWriterWaitInitCall) Return(info InitialInfo, err error) *StreamWriterWaitInitCall { + c.Call = c.Call.Return(info, err) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *StreamWriterWaitInitCall) Do(f func(context.Context) (InitialInfo, error)) *StreamWriterWaitInitCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *StreamWriterWaitInitCall) DoAndReturn(f func(context.Context) (InitialInfo, error)) *StreamWriterWaitInitCall { + c.Call = c.Call.DoAndReturn(f) + return c } // Write mocks base method. @@ -71,7 +122,31 @@ func (m *MockStreamWriter) Write(ctx context.Context, messages []PublicMessage) } // Write indicates an expected call of Write. -func (mr *MockStreamWriterMockRecorder) Write(ctx, messages interface{}) *gomock.Call { +func (mr *MockStreamWriterMockRecorder) Write(ctx, messages any) *StreamWriterWriteCall { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Write", reflect.TypeOf((*MockStreamWriter)(nil).Write), ctx, messages) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Write", reflect.TypeOf((*MockStreamWriter)(nil).Write), ctx, messages) + return &StreamWriterWriteCall{Call: call} +} + +// StreamWriterWriteCall wrap *gomock.Call +type StreamWriterWriteCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *StreamWriterWriteCall) Return(arg0 error) *StreamWriterWriteCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *StreamWriterWriteCall) Do(f func(context.Context, []PublicMessage) error) *StreamWriterWriteCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *StreamWriterWriteCall) DoAndReturn(f func(context.Context, []PublicMessage) error) *StreamWriterWriteCall { + c.Call = c.Call.DoAndReturn(f) + return c } diff --git a/internal/topic/topicwriterinternal/writer_test.go b/internal/topic/topicwriterinternal/writer_test.go index 2be44ed68..7852ca5ac 100644 --- a/internal/topic/topicwriterinternal/writer_test.go +++ b/internal/topic/topicwriterinternal/writer_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) func TestWriterWaitInit(t *testing.T) {