Skip to content

Commit

Permalink
add rm test (apache#192)
Browse files Browse the repository at this point in the history
add test for rm
  • Loading branch information
windWheel authored Aug 22, 2022
1 parent b591b73 commit 40133c5
Show file tree
Hide file tree
Showing 10 changed files with 634 additions and 19 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/agiledragon/gomonkey v2.0.2+incompatible
github.com/apache/dubbo-getty v1.4.8
github.com/dubbogo/gost v1.12.5
github.com/golang/mock v1.6.0
github.com/go-sql-driver/mysql v1.6.0
github.com/google/uuid v1.3.0
github.com/natefinch/lumberjack v2.0.0+incompatible
Expand Down
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1839,4 +1839,4 @@ sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67/go.m
vimagination.zapto.org/byteio v0.0.0-20200222190125-d27cba0f0b10 h1:pxt6fVJP67Hxo1qk8JalUghLlk3abYByl+3e0JYfUlE=
vimagination.zapto.org/byteio v0.0.0-20200222190125-d27cba0f0b10/go.mod h1:fl9OF22g6MTKgvHA1hqMXe/L7+ULWofVTwbC9loGu7A=
vimagination.zapto.org/memio v0.0.0-20200222190306-588ebc67b97d h1:Mp6WiHHuiwHaknxTdxJ8pvC9/B4pOgW1PamKGexG7Fs=
vimagination.zapto.org/memio v0.0.0-20200222190306-588ebc67b97d/go.mod h1:zHGDKp2tyvF4IAfLti4pKYqCJucXYmmKMb3UMrCHK/4=
vimagination.zapto.org/memio v0.0.0-20200222190306-588ebc67b97d/go.mod h1:zHGDKp2tyvF4IAfLti4pKYqCJucXYmmKMb3UMrCHK/4=
384 changes: 384 additions & 0 deletions pkg/rm/rm_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,384 @@
package rm

import (
"context"
"github.com/golang/mock/gomock"
"github.com/seata/seata-go/pkg/protocol/branch"
"reflect"
"sync"
)

// MockResource is a mock of Resource interface.
type MockResource struct {
ctrl *gomock.Controller
recorder *MockResourceMockRecorder
}

// MockResourceMockRecorder is the mock recorder for MockResource.
type MockResourceMockRecorder struct {
mock *MockResource
}

// NewMockResource creates a new mock instance.
func NewMockResource(ctrl *gomock.Controller) *MockResource {
mock := &MockResource{ctrl: ctrl}
mock.recorder = &MockResourceMockRecorder{mock}
return mock
}

// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockResource) EXPECT() *MockResourceMockRecorder {
return m.recorder
}

// GetBranchType mocks base method.
func (m *MockResource) GetBranchType() branch.BranchType {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetBranchType")
ret0, _ := ret[0].(branch.BranchType)
return ret0
}

// GetBranchType indicates an expected call of GetBranchType.
func (mr *MockResourceMockRecorder) GetBranchType() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBranchType", reflect.TypeOf((*MockResource)(nil).GetBranchType))
}

// GetResourceGroupId mocks base method.
func (m *MockResource) GetResourceGroupId() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetResourceGroupId")
ret0, _ := ret[0].(string)
return ret0
}

// GetResourceGroupId indicates an expected call of GetResourceGroupId.
func (mr *MockResourceMockRecorder) GetResourceGroupId() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetResourceGroupId", reflect.TypeOf((*MockResource)(nil).GetResourceGroupId))
}

// GetResourceId mocks base method.
func (m *MockResource) GetResourceId() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetResourceId")
ret0, _ := ret[0].(string)
return ret0
}

// GetResourceId indicates an expected call of GetResourceId.
func (mr *MockResourceMockRecorder) GetResourceId() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetResourceId", reflect.TypeOf((*MockResource)(nil).GetResourceId))
}

// MockResourceManagerInbound is a mock of ResourceManagerInbound interface.
type MockResourceManagerInbound struct {
ctrl *gomock.Controller
recorder *MockResourceManagerInboundMockRecorder
}

// MockResourceManagerInboundMockRecorder is the mock recorder for MockResourceManagerInbound.
type MockResourceManagerInboundMockRecorder struct {
mock *MockResourceManagerInbound
}

// NewMockResourceManagerInbound creates a new mock instance.
func NewMockResourceManagerInbound(ctrl *gomock.Controller) *MockResourceManagerInbound {
mock := &MockResourceManagerInbound{ctrl: ctrl}
mock.recorder = &MockResourceManagerInboundMockRecorder{mock}
return mock
}

// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockResourceManagerInbound) EXPECT() *MockResourceManagerInboundMockRecorder {
return m.recorder
}

// BranchCommit mocks base method.
func (m *MockResourceManagerInbound) BranchCommit(ctx context.Context, resource BranchResource) (branch.BranchStatus, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BranchCommit", ctx, resource)
ret0, _ := ret[0].(branch.BranchStatus)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// BranchCommit indicates an expected call of BranchCommit.
func (mr *MockResourceManagerInboundMockRecorder) BranchCommit(ctx, resource interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BranchCommit", reflect.TypeOf((*MockResourceManagerInbound)(nil).BranchCommit), ctx, resource)
}

// BranchRollback mocks base method.
func (m *MockResourceManagerInbound) BranchRollback(ctx context.Context, resource BranchResource) (branch.BranchStatus, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BranchRollback", ctx, resource)
ret0, _ := ret[0].(branch.BranchStatus)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// BranchRollback indicates an expected call of BranchRollback.
func (mr *MockResourceManagerInboundMockRecorder) BranchRollback(ctx, resource interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BranchRollback", reflect.TypeOf((*MockResourceManagerInbound)(nil).BranchRollback), ctx, resource)
}

// MockResourceManagerOutbound is a mock of ResourceManagerOutbound interface.
type MockResourceManagerOutbound struct {
ctrl *gomock.Controller
recorder *MockResourceManagerOutboundMockRecorder
}

// MockResourceManagerOutboundMockRecorder is the mock recorder for MockResourceManagerOutbound.
type MockResourceManagerOutboundMockRecorder struct {
mock *MockResourceManagerOutbound
}

// NewMockResourceManagerOutbound creates a new mock instance.
func NewMockResourceManagerOutbound(ctrl *gomock.Controller) *MockResourceManagerOutbound {
mock := &MockResourceManagerOutbound{ctrl: ctrl}
mock.recorder = &MockResourceManagerOutboundMockRecorder{mock}
return mock
}

// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockResourceManagerOutbound) EXPECT() *MockResourceManagerOutboundMockRecorder {
return m.recorder
}

// BranchRegister mocks base method.
func (m *MockResourceManagerOutbound) BranchRegister(ctx context.Context, param BranchRegisterParam) (int64, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BranchRegister", ctx, param)
ret0, _ := ret[0].(int64)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// BranchRegister indicates an expected call of BranchRegister.
func (mr *MockResourceManagerOutboundMockRecorder) BranchRegister(ctx, param interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BranchRegister", reflect.TypeOf((*MockResourceManagerOutbound)(nil).BranchRegister), ctx, param)
}

// BranchReport mocks base method.
func (m *MockResourceManagerOutbound) BranchReport(ctx context.Context, param BranchReportParam) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BranchReport", ctx, param)
ret0, _ := ret[0].(error)
return ret0
}

// BranchReport indicates an expected call of BranchReport.
func (mr *MockResourceManagerOutboundMockRecorder) BranchReport(ctx, param interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BranchReport", reflect.TypeOf((*MockResourceManagerOutbound)(nil).BranchReport), ctx, param)
}

// LockQuery mocks base method.
func (m *MockResourceManagerOutbound) LockQuery(ctx context.Context, param LockQueryParam) (bool, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "LockQuery", ctx, param)
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// LockQuery indicates an expected call of LockQuery.
func (mr *MockResourceManagerOutboundMockRecorder) LockQuery(ctx, param interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LockQuery", reflect.TypeOf((*MockResourceManagerOutbound)(nil).LockQuery), ctx, param)
}

// MockResourceManager is a mock of ResourceManager interface.
type MockResourceManager struct {
ctrl *gomock.Controller
recorder *MockResourceManagerMockRecorder
}

// MockResourceManagerMockRecorder is the mock recorder for MockResourceManager.
type MockResourceManagerMockRecorder struct {
mock *MockResourceManager
}

// NewMockResourceManager creates a new mock instance.
func NewMockResourceManager(ctrl *gomock.Controller) *MockResourceManager {
mock := &MockResourceManager{ctrl: ctrl}
mock.recorder = &MockResourceManagerMockRecorder{mock}
return mock
}

// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockResourceManager) EXPECT() *MockResourceManagerMockRecorder {
return m.recorder
}

// BranchCommit mocks base method.
func (m *MockResourceManager) BranchCommit(ctx context.Context, resource BranchResource) (branch.BranchStatus, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BranchCommit", ctx, resource)
ret0, _ := ret[0].(branch.BranchStatus)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// BranchCommit indicates an expected call of BranchCommit.
func (mr *MockResourceManagerMockRecorder) BranchCommit(ctx, resource interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BranchCommit", reflect.TypeOf((*MockResourceManager)(nil).BranchCommit), ctx, resource)
}

// BranchRegister mocks base method.
func (m *MockResourceManager) BranchRegister(ctx context.Context, param BranchRegisterParam) (int64, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BranchRegister", ctx, param)
ret0, _ := ret[0].(int64)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// BranchRegister indicates an expected call of BranchRegister.
func (mr *MockResourceManagerMockRecorder) BranchRegister(ctx, param interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BranchRegister", reflect.TypeOf((*MockResourceManager)(nil).BranchRegister), ctx, param)
}

// BranchReport mocks base method.
func (m *MockResourceManager) BranchReport(ctx context.Context, param BranchReportParam) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BranchReport", ctx, param)
ret0, _ := ret[0].(error)
return ret0
}

// BranchReport indicates an expected call of BranchReport.
func (mr *MockResourceManagerMockRecorder) BranchReport(ctx, param interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BranchReport", reflect.TypeOf((*MockResourceManager)(nil).BranchReport), ctx, param)
}

// BranchRollback mocks base method.
func (m *MockResourceManager) BranchRollback(ctx context.Context, resource BranchResource) (branch.BranchStatus, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BranchRollback", ctx, resource)
ret0, _ := ret[0].(branch.BranchStatus)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// BranchRollback indicates an expected call of BranchRollback.
func (mr *MockResourceManagerMockRecorder) BranchRollback(ctx, resource interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BranchRollback", reflect.TypeOf((*MockResourceManager)(nil).BranchRollback), ctx, resource)
}

// GetBranchType mocks base method.
func (m *MockResourceManager) GetBranchType() branch.BranchType {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetBranchType")
ret0, _ := ret[0].(branch.BranchType)
return ret0
}

// GetBranchType indicates an expected call of GetBranchType.
func (mr *MockResourceManagerMockRecorder) GetBranchType() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBranchType", reflect.TypeOf((*MockResourceManager)(nil).GetBranchType))
}

// GetCachedResources mocks base method.
func (m *MockResourceManager) GetCachedResources() *sync.Map {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetCachedResources")
ret0, _ := ret[0].(*sync.Map)
return ret0
}

// GetCachedResources indicates an expected call of GetCachedResources.
func (mr *MockResourceManagerMockRecorder) GetCachedResources() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCachedResources", reflect.TypeOf((*MockResourceManager)(nil).GetCachedResources))
}

// LockQuery mocks base method.
func (m *MockResourceManager) LockQuery(ctx context.Context, param LockQueryParam) (bool, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "LockQuery", ctx, param)
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// LockQuery indicates an expected call of LockQuery.
func (mr *MockResourceManagerMockRecorder) LockQuery(ctx, param interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LockQuery", reflect.TypeOf((*MockResourceManager)(nil).LockQuery), ctx, param)
}

// RegisterResource mocks base method.
func (m *MockResourceManager) RegisterResource(resource Resource) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "RegisterResource", resource)
ret0, _ := ret[0].(error)
return ret0
}

// RegisterResource indicates an expected call of RegisterResource.
func (mr *MockResourceManagerMockRecorder) RegisterResource(resource interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterResource", reflect.TypeOf((*MockResourceManager)(nil).RegisterResource), resource)
}

// UnregisterResource mocks base method.
func (m *MockResourceManager) UnregisterResource(resource Resource) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UnregisterResource", resource)
ret0, _ := ret[0].(error)
return ret0
}

// UnregisterResource indicates an expected call of UnregisterResource.
func (mr *MockResourceManagerMockRecorder) UnregisterResource(resource interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnregisterResource", reflect.TypeOf((*MockResourceManager)(nil).UnregisterResource), resource)
}

// MockResourceManagerGetter is a mock of ResourceManagerGetter interface.
type MockResourceManagerGetter struct {
ctrl *gomock.Controller
recorder *MockResourceManagerGetterMockRecorder
}

// MockResourceManagerGetterMockRecorder is the mock recorder for MockResourceManagerGetter.
type MockResourceManagerGetterMockRecorder struct {
mock *MockResourceManagerGetter
}

// NewMockResourceManagerGetter creates a new mock instance.
func NewMockResourceManagerGetter(ctrl *gomock.Controller) *MockResourceManagerGetter {
mock := &MockResourceManagerGetter{ctrl: ctrl}
mock.recorder = &MockResourceManagerGetterMockRecorder{mock}
return mock
}

// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockResourceManagerGetter) EXPECT() *MockResourceManagerGetterMockRecorder {
return m.recorder
}

// GetResourceManager mocks base method.
func (m *MockResourceManagerGetter) GetResourceManager(branchType branch.BranchType) ResourceManager {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetResourceManager", branchType)
ret0, _ := ret[0].(ResourceManager)
return ret0
}

// GetResourceManager indicates an expected call of GetResourceManager.
func (mr *MockResourceManagerGetterMockRecorder) GetResourceManager(branchType interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetResourceManager", reflect.TypeOf((*MockResourceManagerGetter)(nil).GetResourceManager), branchType)
}
Loading

0 comments on commit 40133c5

Please sign in to comment.