From 58cf3ba729b1a6f63226f9247323d52527777367 Mon Sep 17 00:00:00 2001 From: Mulavar <978007503@qq.com> Date: Sat, 16 Sep 2023 21:20:00 +0800 Subject: [PATCH] test: add unit test for /arana/pkg/sequence/... package --- pkg/runtime/runtime.go | 2 +- pkg/sequence/group/group_test.go | 2 +- pkg/sequence/snowflake/snowflake_test.go | 3 +- testdata/mock_rt_runtime.go | 133 ----------------------- 4 files changed, 4 insertions(+), 136 deletions(-) delete mode 100644 testdata/mock_rt_runtime.go diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index 6288cb97..e57b5e3d 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -15,7 +15,7 @@ * limitations under the License. */ -//go:generate mockgen -destination=../../testdata/mock_rt_runtime.go -package=testdata . Runtime +//go:generate mockgen -destination=./mock_runtime.go -package=runtime . Runtime package runtime import ( diff --git a/pkg/sequence/group/group_test.go b/pkg/sequence/group/group_test.go index f8a22aea..dd6af719 100644 --- a/pkg/sequence/group/group_test.go +++ b/pkg/sequence/group/group_test.go @@ -77,7 +77,7 @@ func Test_groupSequence_Acquire(t *testing.T) { mockTx.EXPECT().Rollback(gomock.Any()).Return(mockRes, uint16(0), nil).AnyTimes() // build mock runtime - mockRt := testdata.NewMockRuntime(ctrl) + mockRt := runtime.NewMockRuntime(ctrl) mockRt.EXPECT().Begin(gomock.Any()).Return(mockTx, nil).AnyTimes() runtime.Register(tenant, schema, mockRt) diff --git a/pkg/sequence/snowflake/snowflake_test.go b/pkg/sequence/snowflake/snowflake_test.go index afba0639..96b15fe8 100644 --- a/pkg/sequence/snowflake/snowflake_test.go +++ b/pkg/sequence/snowflake/snowflake_test.go @@ -33,6 +33,7 @@ import ( import ( "github.com/arana-db/arana/pkg/proto" + "github.com/arana-db/arana/pkg/runtime" "github.com/arana-db/arana/testdata" ) @@ -68,7 +69,7 @@ func Test_snowflakeSequence_Acquire(t *testing.T) { mockTx.EXPECT().Rollback(gomock.Any()).Return(mockRes, uint16(0), nil).AnyTimes() // build mock runtime - mockRt := testdata.NewMockRuntime(ctrl) + mockRt := runtime.NewMockRuntime(ctrl) mockRt.EXPECT().Begin(gomock.Any()).Return(mockTx, nil).AnyTimes() ctx := context.WithValue(context.Background(), proto.RuntimeCtxKey{}, mockRt) diff --git a/testdata/mock_rt_runtime.go b/testdata/mock_rt_runtime.go deleted file mode 100644 index 05ee557d..00000000 --- a/testdata/mock_rt_runtime.go +++ /dev/null @@ -1,133 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/arana-db/arana/pkg/runtime (interfaces: Runtime) - -// Package testdata is a generated GoMock package. -package testdata - -import ( - context "context" - reflect "reflect" -) - -import ( - gomock "github.com/golang/mock/gomock" -) - -import ( - proto "github.com/arana-db/arana/pkg/proto" - runtime "github.com/arana-db/arana/pkg/runtime" - namespace "github.com/arana-db/arana/pkg/runtime/namespace" -) - -// MockRuntime is a mock of Runtime interface. -type MockRuntime struct { - ctrl *gomock.Controller - recorder *MockRuntimeMockRecorder -} - -// MockRuntimeMockRecorder is the mock recorder for MockRuntime. -type MockRuntimeMockRecorder struct { - mock *MockRuntime -} - -// NewMockRuntime creates a new mock instance. -func NewMockRuntime(ctrl *gomock.Controller) *MockRuntime { - mock := &MockRuntime{ctrl: ctrl} - mock.recorder = &MockRuntimeMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockRuntime) EXPECT() *MockRuntimeMockRecorder { - return m.recorder -} - -// Begin mocks base method. -func (m *MockRuntime) Begin(arg0 context.Context, arg1 ...runtime.TxHook) (proto.Tx, error) { - m.ctrl.T.Helper() - varargs := []interface{}{arg0} - for _, a := range arg1 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Begin", varargs...) - ret0, _ := ret[0].(proto.Tx) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Begin indicates an expected call of Begin. -func (mr *MockRuntimeMockRecorder) Begin(arg0 interface{}, arg1 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0}, arg1...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Begin", reflect.TypeOf((*MockRuntime)(nil).Begin), varargs...) -} - -// Exec mocks base method. -func (m *MockRuntime) Exec(arg0 context.Context, arg1, arg2 string, arg3 ...proto.Value) (proto.Result, error) { - m.ctrl.T.Helper() - varargs := []interface{}{arg0, arg1, arg2} - for _, a := range arg3 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Exec", varargs...) - ret0, _ := ret[0].(proto.Result) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Exec indicates an expected call of Exec. -func (mr *MockRuntimeMockRecorder) Exec(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Exec", reflect.TypeOf((*MockRuntime)(nil).Exec), varargs...) -} - -// Execute mocks base method. -func (m *MockRuntime) Execute(arg0 *proto.Context) (proto.Result, uint16, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Execute", arg0) - ret0, _ := ret[0].(proto.Result) - ret1, _ := ret[1].(uint16) - ret2, _ := ret[2].(error) - return ret0, ret1, ret2 -} - -// Execute indicates an expected call of Execute. -func (mr *MockRuntimeMockRecorder) Execute(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockRuntime)(nil).Execute), arg0) -} - -// Namespace mocks base method. -func (m *MockRuntime) Namespace() *namespace.Namespace { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Namespace") - ret0, _ := ret[0].(*namespace.Namespace) - return ret0 -} - -// Namespace indicates an expected call of Namespace. -func (mr *MockRuntimeMockRecorder) Namespace() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Namespace", reflect.TypeOf((*MockRuntime)(nil).Namespace)) -} - -// Query mocks base method. -func (m *MockRuntime) Query(arg0 context.Context, arg1, arg2 string, arg3 ...proto.Value) (proto.Result, error) { - m.ctrl.T.Helper() - varargs := []interface{}{arg0, arg1, arg2} - for _, a := range arg3 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Query", varargs...) - ret0, _ := ret[0].(proto.Result) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Query indicates an expected call of Query. -func (mr *MockRuntimeMockRecorder) Query(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Query", reflect.TypeOf((*MockRuntime)(nil).Query), varargs...) -}