From e9c2292776bd84624226853ead9d9fcc8cdd05f1 Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Thu, 5 Apr 2018 15:14:47 +0200 Subject: [PATCH] Switch mockgen to reflect mode (#800) Switch mockgen to use reflect mode as source mode does not support vendored packages. --- Makefile | 6 +- _assets/ci/Jenkinsfile-manual | 19 ++-- geth/mailservice/mailservice_mock.go | 2 +- geth/notifications/push/fcm/client.go | 4 +- geth/notifications/push/fcm/client_mock.go | 86 ++++++++++++++----- geth/notifications/push/fcm/notification.go | 2 +- .../push/fcm/notification_test.go | 4 +- geth/transactions/fake/mock.go | 52 +++++------ 8 files changed, 111 insertions(+), 64 deletions(-) diff --git a/Makefile b/Makefile index fe8189464..67d280ff0 100644 --- a/Makefile +++ b/Makefile @@ -114,9 +114,9 @@ mock-install: ##@other Install mocking tools go get -u github.com/golang/mock/mockgen mock: ##@other Regenerate mocks - mockgen -source=geth/mailservice/mailservice.go -destination=geth/mailservice/mailservice_mock.go -package=mailservice - mockgen -source=geth/notifications/push/fcm/client.go -destination=geth/notifications/push/fcm/client_mock.go -package=fcm -imports fcm=github.com/NaySoftware/go-fcm - mockgen -source=geth/transactions/fake/txservice.go -destination=geth/transactions/fake/mock.go -package=fake + mockgen -package=mailservice -destination=geth/mailservice/mailservice_mock.go github.com/status-im/status-go/geth/mailservice ServiceProvider + mockgen -package=fcm -destination=geth/notifications/push/fcm/client_mock.go github.com/status-im/status-go/geth/notifications/push/fcm FirebaseClient,Notifier + mockgen -package=fake -destination=geth/transactions/fake/mock.go github.com/status-im/status-go/geth/transactions/fake PublicTransactionPoolAPI docker-test: ##@tests Run tests in a docker container with golang. docker run --privileged --rm -it -v "$(shell pwd):$(DOCKER_TEST_WORKDIR)" -w "$(DOCKER_TEST_WORKDIR)" $(DOCKER_TEST_IMAGE) go test ${ARGS} diff --git a/_assets/ci/Jenkinsfile-manual b/_assets/ci/Jenkinsfile-manual index 2e6756556..16c5052f9 100644 --- a/_assets/ci/Jenkinsfile-manual +++ b/_assets/ci/Jenkinsfile-manual @@ -17,10 +17,19 @@ def getVersion(branch, sha, buildNumber) { node('linux') { env.GOPATH = "${env.WORKSPACE}" + env.PATH = "${env.PATH}:${env.GOPATH}/bin" cloneDir = 'src/github.com/status-im/status-go' paramBranch = env.branch ? ('*/' + env.branch) : '*/develop' + dir(cloneDir) { + try { + deleteDir() + } catch (err) { + echo "failure while cleaning the directory" + } + } + checkout( changelog: false, poll: true, @@ -48,12 +57,10 @@ node('linux') { } stage('Test') { - sh ''' - make lint-install - make mock-install - - make ci - ''' + dir(cloneDir) { + sh 'make setup' + sh 'make ci' + } } stage('Build') { diff --git a/geth/mailservice/mailservice_mock.go b/geth/mailservice/mailservice_mock.go index db328277e..6e5d789fb 100644 --- a/geth/mailservice/mailservice_mock.go +++ b/geth/mailservice/mailservice_mock.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: geth/mailservice/mailservice.go +// Source: github.com/status-im/status-go/geth/mailservice (interfaces: ServiceProvider) // Package mailservice is a generated GoMock package. package mailservice diff --git a/geth/notifications/push/fcm/client.go b/geth/notifications/push/fcm/client.go index bc2ae434b..163ff202b 100644 --- a/geth/notifications/push/fcm/client.go +++ b/geth/notifications/push/fcm/client.go @@ -2,8 +2,8 @@ package fcm import "github.com/NaySoftware/go-fcm" -// firebaseClient is a copy of "go-fcm" client methods. -type firebaseClient interface { +// FirebaseClient is a copy of "go-fcm" client methods. +type FirebaseClient interface { NewFcmRegIdsMsg(tokens []string, body interface{}) *fcm.FcmClient Send() (*fcm.FcmResponseStatus, error) SetNotificationPayload(payload *fcm.NotificationPayload) *fcm.FcmClient diff --git a/geth/notifications/push/fcm/client_mock.go b/geth/notifications/push/fcm/client_mock.go index 428775205..d3e7a4154 100644 --- a/geth/notifications/push/fcm/client_mock.go +++ b/geth/notifications/push/fcm/client_mock.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: geth/notifications/push/fcm/client.go +// Source: github.com/status-im/status-go/geth/notifications/push/fcm (interfaces: FirebaseClient,Notifier) // Package fcm is a generated GoMock package. package fcm @@ -10,43 +10,43 @@ import ( reflect "reflect" ) -// MockfirebaseClient is a mock of firebaseClient interface -type MockfirebaseClient struct { +// MockFirebaseClient is a mock of FirebaseClient interface +type MockFirebaseClient struct { ctrl *gomock.Controller - recorder *MockfirebaseClientMockRecorder + recorder *MockFirebaseClientMockRecorder } -// MockfirebaseClientMockRecorder is the mock recorder for MockfirebaseClient -type MockfirebaseClientMockRecorder struct { - mock *MockfirebaseClient +// MockFirebaseClientMockRecorder is the mock recorder for MockFirebaseClient +type MockFirebaseClientMockRecorder struct { + mock *MockFirebaseClient } -// NewMockfirebaseClient creates a new mock instance -func NewMockfirebaseClient(ctrl *gomock.Controller) *MockfirebaseClient { - mock := &MockfirebaseClient{ctrl: ctrl} - mock.recorder = &MockfirebaseClientMockRecorder{mock} +// NewMockFirebaseClient creates a new mock instance +func NewMockFirebaseClient(ctrl *gomock.Controller) *MockFirebaseClient { + mock := &MockFirebaseClient{ctrl: ctrl} + mock.recorder = &MockFirebaseClientMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use -func (m *MockfirebaseClient) EXPECT() *MockfirebaseClientMockRecorder { +func (m *MockFirebaseClient) EXPECT() *MockFirebaseClientMockRecorder { return m.recorder } // NewFcmRegIdsMsg mocks base method -func (m *MockfirebaseClient) NewFcmRegIdsMsg(tokens []string, body interface{}) *go_fcm.FcmClient { - ret := m.ctrl.Call(m, "NewFcmRegIdsMsg", tokens, body) +func (m *MockFirebaseClient) NewFcmRegIdsMsg(arg0 []string, arg1 interface{}) *go_fcm.FcmClient { + ret := m.ctrl.Call(m, "NewFcmRegIdsMsg", arg0, arg1) ret0, _ := ret[0].(*go_fcm.FcmClient) return ret0 } // NewFcmRegIdsMsg indicates an expected call of NewFcmRegIdsMsg -func (mr *MockfirebaseClientMockRecorder) NewFcmRegIdsMsg(tokens, body interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewFcmRegIdsMsg", reflect.TypeOf((*MockfirebaseClient)(nil).NewFcmRegIdsMsg), tokens, body) +func (mr *MockFirebaseClientMockRecorder) NewFcmRegIdsMsg(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewFcmRegIdsMsg", reflect.TypeOf((*MockFirebaseClient)(nil).NewFcmRegIdsMsg), arg0, arg1) } // Send mocks base method -func (m *MockfirebaseClient) Send() (*go_fcm.FcmResponseStatus, error) { +func (m *MockFirebaseClient) Send() (*go_fcm.FcmResponseStatus, error) { ret := m.ctrl.Call(m, "Send") ret0, _ := ret[0].(*go_fcm.FcmResponseStatus) ret1, _ := ret[1].(error) @@ -54,18 +54,58 @@ func (m *MockfirebaseClient) Send() (*go_fcm.FcmResponseStatus, error) { } // Send indicates an expected call of Send -func (mr *MockfirebaseClientMockRecorder) Send() *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockfirebaseClient)(nil).Send)) +func (mr *MockFirebaseClientMockRecorder) Send() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockFirebaseClient)(nil).Send)) } // SetNotificationPayload mocks base method -func (m *MockfirebaseClient) SetNotificationPayload(payload *go_fcm.NotificationPayload) *go_fcm.FcmClient { - ret := m.ctrl.Call(m, "SetNotificationPayload", payload) +func (m *MockFirebaseClient) SetNotificationPayload(arg0 *go_fcm.NotificationPayload) *go_fcm.FcmClient { + ret := m.ctrl.Call(m, "SetNotificationPayload", arg0) ret0, _ := ret[0].(*go_fcm.FcmClient) return ret0 } // SetNotificationPayload indicates an expected call of SetNotificationPayload -func (mr *MockfirebaseClientMockRecorder) SetNotificationPayload(payload interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetNotificationPayload", reflect.TypeOf((*MockfirebaseClient)(nil).SetNotificationPayload), payload) +func (mr *MockFirebaseClientMockRecorder) SetNotificationPayload(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetNotificationPayload", reflect.TypeOf((*MockFirebaseClient)(nil).SetNotificationPayload), arg0) +} + +// MockNotifier is a mock of Notifier interface +type MockNotifier struct { + ctrl *gomock.Controller + recorder *MockNotifierMockRecorder +} + +// MockNotifierMockRecorder is the mock recorder for MockNotifier +type MockNotifierMockRecorder struct { + mock *MockNotifier +} + +// NewMockNotifier creates a new mock instance +func NewMockNotifier(ctrl *gomock.Controller) *MockNotifier { + mock := &MockNotifier{ctrl: ctrl} + mock.recorder = &MockNotifierMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockNotifier) EXPECT() *MockNotifierMockRecorder { + return m.recorder +} + +// Send mocks base method +func (m *MockNotifier) Send(arg0 string, arg1 go_fcm.NotificationPayload, arg2 ...string) error { + varargs := []interface{}{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Send", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Send indicates an expected call of Send +func (mr *MockNotifierMockRecorder) Send(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { + varargs := append([]interface{}{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockNotifier)(nil).Send), varargs...) } diff --git a/geth/notifications/push/fcm/notification.go b/geth/notifications/push/fcm/notification.go index 4eb3dcd83..9ba86b081 100644 --- a/geth/notifications/push/fcm/notification.go +++ b/geth/notifications/push/fcm/notification.go @@ -16,7 +16,7 @@ type NotificationConstructor func() Notifier // Notification represents messaging provider for notifications. type Notification struct { - client firebaseClient + client FirebaseClient } // NewNotification Firebase Cloud Messaging client constructor. diff --git a/geth/notifications/push/fcm/notification_test.go b/geth/notifications/push/fcm/notification_test.go index 6c429dd5a..c22419eed 100644 --- a/geth/notifications/push/fcm/notification_test.go +++ b/geth/notifications/push/fcm/notification_test.go @@ -16,13 +16,13 @@ func TestFCMClientTestSuite(t *testing.T) { type NotifierTestSuite struct { suite.Suite - fcmClientMock *MockfirebaseClient + fcmClientMock *MockFirebaseClient fcmClientMockCtrl *gomock.Controller } func (s *NotifierTestSuite) SetupTest() { s.fcmClientMockCtrl = gomock.NewController(s.T()) - s.fcmClientMock = NewMockfirebaseClient(s.fcmClientMockCtrl) + s.fcmClientMock = NewMockFirebaseClient(s.fcmClientMockCtrl) } func (s *NotifierTestSuite) TearDownTest() { diff --git a/geth/transactions/fake/mock.go b/geth/transactions/fake/mock.go index 460111508..8c1589c83 100644 --- a/geth/transactions/fake/mock.go +++ b/geth/transactions/fake/mock.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: geth/transactions/fake/txservice.go +// Source: github.com/status-im/status-go/geth/transactions/fake (interfaces: PublicTransactionPoolAPI) // Package fake is a generated GoMock package. package fake @@ -37,54 +37,54 @@ func (m *MockPublicTransactionPoolAPI) EXPECT() *MockPublicTransactionPoolAPIMoc return m.recorder } -// GasPrice mocks base method -func (m *MockPublicTransactionPoolAPI) GasPrice(ctx context.Context) (*big.Int, error) { - ret := m.ctrl.Call(m, "GasPrice", ctx) - ret0, _ := ret[0].(*big.Int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GasPrice indicates an expected call of GasPrice -func (mr *MockPublicTransactionPoolAPIMockRecorder) GasPrice(ctx interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GasPrice", reflect.TypeOf((*MockPublicTransactionPoolAPI)(nil).GasPrice), ctx) -} - // EstimateGas mocks base method -func (m *MockPublicTransactionPoolAPI) EstimateGas(ctx context.Context, args CallArgs) (hexutil.Uint64, error) { - ret := m.ctrl.Call(m, "EstimateGas", ctx, args) +func (m *MockPublicTransactionPoolAPI) EstimateGas(arg0 context.Context, arg1 CallArgs) (hexutil.Uint64, error) { + ret := m.ctrl.Call(m, "EstimateGas", arg0, arg1) ret0, _ := ret[0].(hexutil.Uint64) ret1, _ := ret[1].(error) return ret0, ret1 } // EstimateGas indicates an expected call of EstimateGas -func (mr *MockPublicTransactionPoolAPIMockRecorder) EstimateGas(ctx, args interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EstimateGas", reflect.TypeOf((*MockPublicTransactionPoolAPI)(nil).EstimateGas), ctx, args) +func (mr *MockPublicTransactionPoolAPIMockRecorder) EstimateGas(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EstimateGas", reflect.TypeOf((*MockPublicTransactionPoolAPI)(nil).EstimateGas), arg0, arg1) +} + +// GasPrice mocks base method +func (m *MockPublicTransactionPoolAPI) GasPrice(arg0 context.Context) (*big.Int, error) { + ret := m.ctrl.Call(m, "GasPrice", arg0) + ret0, _ := ret[0].(*big.Int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GasPrice indicates an expected call of GasPrice +func (mr *MockPublicTransactionPoolAPIMockRecorder) GasPrice(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GasPrice", reflect.TypeOf((*MockPublicTransactionPoolAPI)(nil).GasPrice), arg0) } // GetTransactionCount mocks base method -func (m *MockPublicTransactionPoolAPI) GetTransactionCount(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*hexutil.Uint64, error) { - ret := m.ctrl.Call(m, "GetTransactionCount", ctx, address, blockNr) +func (m *MockPublicTransactionPoolAPI) GetTransactionCount(arg0 context.Context, arg1 common.Address, arg2 rpc.BlockNumber) (*hexutil.Uint64, error) { + ret := m.ctrl.Call(m, "GetTransactionCount", arg0, arg1, arg2) ret0, _ := ret[0].(*hexutil.Uint64) ret1, _ := ret[1].(error) return ret0, ret1 } // GetTransactionCount indicates an expected call of GetTransactionCount -func (mr *MockPublicTransactionPoolAPIMockRecorder) GetTransactionCount(ctx, address, blockNr interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransactionCount", reflect.TypeOf((*MockPublicTransactionPoolAPI)(nil).GetTransactionCount), ctx, address, blockNr) +func (mr *MockPublicTransactionPoolAPIMockRecorder) GetTransactionCount(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransactionCount", reflect.TypeOf((*MockPublicTransactionPoolAPI)(nil).GetTransactionCount), arg0, arg1, arg2) } // SendRawTransaction mocks base method -func (m *MockPublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error) { - ret := m.ctrl.Call(m, "SendRawTransaction", ctx, encodedTx) +func (m *MockPublicTransactionPoolAPI) SendRawTransaction(arg0 context.Context, arg1 hexutil.Bytes) (common.Hash, error) { + ret := m.ctrl.Call(m, "SendRawTransaction", arg0, arg1) ret0, _ := ret[0].(common.Hash) ret1, _ := ret[1].(error) return ret0, ret1 } // SendRawTransaction indicates an expected call of SendRawTransaction -func (mr *MockPublicTransactionPoolAPIMockRecorder) SendRawTransaction(ctx, encodedTx interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendRawTransaction", reflect.TypeOf((*MockPublicTransactionPoolAPI)(nil).SendRawTransaction), ctx, encodedTx) +func (mr *MockPublicTransactionPoolAPIMockRecorder) SendRawTransaction(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendRawTransaction", reflect.TypeOf((*MockPublicTransactionPoolAPI)(nil).SendRawTransaction), arg0, arg1) }