Update PN tests

This commit is contained in:
Eugene 2017-10-11 16:52:11 +03:00 committed by Evgeny Danienko
parent 804ed7c10c
commit c304d3e7ae
No known key found for this signature in database
GPG Key ID: BC8C34D8B45BECBF
4 changed files with 101 additions and 149 deletions

View File

@ -136,6 +136,7 @@ mock-install: ##@other Install mocking tools
mock: ##@other Regenerate mocks
mockgen -source=geth/common/types.go -destination=geth/common/types_mock.go -package=common
mockgen -source=geth/common/notification.go -destination=geth/common/notification_mock.go -package=common -imports fcm=github.com/NaySoftware/go-fcm
mockgen -source=geth/notification/fcm/client.go -destination=geth/notification/fcm/client_mock.go -package=fcm -imports fcm=github.com/NaySoftware/go-fcm
test: ##@tests Run unit and integration tests
build/env.sh go test $(UNIT_TEST_PACKAGES)

View File

@ -5,159 +5,46 @@
package common
import (
go_fcm "github.com/NaySoftware/go-fcm"
gomock "github.com/golang/mock/gomock"
message "github.com/status-im/status-go/geth/notification/message"
reflect "reflect"
)
// MockNotification is a mock of Notification interface
type MockNotification struct {
// MockNotifier is a mock of Notifier interface
type MockNotifier struct {
ctrl *gomock.Controller
recorder *MockNotificationMockRecorder
recorder *MockNotifierMockRecorder
}
// MockNotificationMockRecorder is the mock recorder for MockNotification
type MockNotificationMockRecorder struct {
mock *MockNotification
// MockNotifierMockRecorder is the mock recorder for MockNotifier
type MockNotifierMockRecorder struct {
mock *MockNotifier
}
// NewMockNotification creates a new mock instance
func NewMockNotification(ctrl *gomock.Controller) *MockNotification {
mock := &MockNotification{ctrl: ctrl}
mock.recorder = &MockNotificationMockRecorder{mock}
// 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 *MockNotification) EXPECT() *MockNotificationMockRecorder {
func (m *MockNotifier) EXPECT() *MockNotifierMockRecorder {
return m.recorder
}
// Notify mocks base method
func (m *MockNotification) Notify(token string, msg *message.Message) (string, error) {
ret := m.ctrl.Call(m, "Notify", token, msg)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Notify indicates an expected call of Notify
func (mr *MockNotificationMockRecorder) Notify(token, msg interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Notify", reflect.TypeOf((*MockNotification)(nil).Notify), token, msg)
}
// MockMessagingProvider is a mock of MessagingProvider interface
type MockMessagingProvider struct {
ctrl *gomock.Controller
recorder *MockMessagingProviderMockRecorder
}
// MockMessagingProviderMockRecorder is the mock recorder for MockMessagingProvider
type MockMessagingProviderMockRecorder struct {
mock *MockMessagingProvider
}
// NewMockMessagingProvider creates a new mock instance
func NewMockMessagingProvider(ctrl *gomock.Controller) *MockMessagingProvider {
mock := &MockMessagingProvider{ctrl: ctrl}
mock.recorder = &MockMessagingProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockMessagingProvider) EXPECT() *MockMessagingProviderMockRecorder {
return m.recorder
}
// SetMessage mocks base method
func (m *MockMessagingProvider) SetMessage(ids []string, body interface{}) {
m.ctrl.Call(m, "SetMessage", ids, body)
}
// SetMessage indicates an expected call of SetMessage
func (mr *MockMessagingProviderMockRecorder) SetMessage(ids, body interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMessage", reflect.TypeOf((*MockMessagingProvider)(nil).SetMessage), ids, body)
}
// SetPayload mocks base method
func (m *MockMessagingProvider) SetPayload(payload *message.Payload) {
m.ctrl.Call(m, "SetPayload", payload)
}
// SetPayload indicates an expected call of SetPayload
func (mr *MockMessagingProviderMockRecorder) SetPayload(payload interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPayload", reflect.TypeOf((*MockMessagingProvider)(nil).SetPayload), payload)
}
// Send mocks base method
func (m *MockMessagingProvider) Send() error {
ret := m.ctrl.Call(m, "Send")
func (m *MockNotifier) Notify(body interface{}, tokens ...string) error {
varargs := []interface{}{body}
for _, a := range tokens {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "Notify", varargs...)
ret0, _ := ret[0].(error)
return ret0
}
// Send indicates an expected call of Send
func (mr *MockMessagingProviderMockRecorder) Send() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockMessagingProvider)(nil).Send))
}
// MockFirebaseClient is a mock of FirebaseClient interface
type MockFirebaseClient struct {
ctrl *gomock.Controller
recorder *MockFirebaseClientMockRecorder
}
// 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}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockFirebaseClient) EXPECT() *MockFirebaseClientMockRecorder {
return m.recorder
}
// NewFcmRegIdsMsg mocks base method
func (m *MockFirebaseClient) NewFcmRegIdsMsg(list []string, body interface{}) *go_fcm.FcmClient {
ret := m.ctrl.Call(m, "NewFcmRegIdsMsg", list, body)
ret0, _ := ret[0].(*go_fcm.FcmClient)
return ret0
}
// NewFcmRegIdsMsg indicates an expected call of NewFcmRegIdsMsg
func (mr *MockFirebaseClientMockRecorder) NewFcmRegIdsMsg(list, body interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewFcmRegIdsMsg", reflect.TypeOf((*MockFirebaseClient)(nil).NewFcmRegIdsMsg), list, body)
}
// Send mocks base method
func (m *MockFirebaseClient) Send() (*go_fcm.FcmResponseStatus, error) {
ret := m.ctrl.Call(m, "Send")
ret0, _ := ret[0].(*go_fcm.FcmResponseStatus)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// 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))
}
// SetNotificationPayload mocks base method
func (m *MockFirebaseClient) SetNotificationPayload(payload *go_fcm.NotificationPayload) *go_fcm.FcmClient {
ret := m.ctrl.Call(m, "SetNotificationPayload", payload)
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)
// Notify indicates an expected call of Notify
func (mr *MockNotifierMockRecorder) Notify(body interface{}, tokens ...interface{}) *gomock.Call {
varargs := append([]interface{}{body}, tokens...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Notify", reflect.TypeOf((*MockNotifier)(nil).Notify), varargs...)
}

View File

@ -0,0 +1,71 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: geth/notification/fcm/client.go
// Package fcm is a generated GoMock package.
package fcm
import (
go_fcm "github.com/NaySoftware/go-fcm"
gomock "github.com/golang/mock/gomock"
reflect "reflect"
)
// MockFirebaseClient is a mock of FirebaseClient interface
type MockFirebaseClient struct {
ctrl *gomock.Controller
recorder *MockFirebaseClientMockRecorder
}
// 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}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
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)
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)
}
// Send mocks base method
func (m *MockFirebaseClient) Send() (*go_fcm.FcmResponseStatus, error) {
ret := m.ctrl.Call(m, "Send")
ret0, _ := ret[0].(*go_fcm.FcmResponseStatus)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// 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))
}
// SetNotificationPayload mocks base method
func (m *MockFirebaseClient) SetNotificationPayload(payload *go_fcm.NotificationPayload) *go_fcm.FcmClient {
ret := m.ctrl.Call(m, "SetNotificationPayload", payload)
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)
}

View File

@ -11,32 +11,26 @@ import (
)
func TestFCMClientTestSuite(t *testing.T) {
suite.Run(t, new(FCMProviderTestSuite))
suite.Run(t, new(NotifierTestSuite))
}
type FCMProviderTestSuite struct {
type NotifierTestSuite struct {
t.BaseTestSuite
fcmClientMock *MockFirebaseClient
fcmClientMockCtrl *gomock.Controller
}
func (s *FCMProviderTestSuite) SetupTest() {
func (s *NotifierTestSuite) SetupTest() {
s.fcmClientMockCtrl = gomock.NewController(s.T())
s.fcmClientMock = NewMockFirebaseClient(s.fcmClientMockCtrl)
}
func (s *FCMProviderTestSuite) TearDownTest() {
func (s *NotifierTestSuite) TearDownTest() {
s.fcmClientMockCtrl.Finish()
}
func (s *FCMProviderTestSuite) TestNewFCMClient() {
fcmClient := Notifier{s.fcmClientMock}
s.Require().NotNil(fcmClient)
}
func (s *FCMProviderTestSuite) TestNotifySuccess() {
func (s *NotifierTestSuite) TestNotifySuccess() {
fcmPayload := getPayload()
ids := []string{"1"}
body := interface{}("body")
@ -48,12 +42,11 @@ func (s *FCMProviderTestSuite) TestNotifySuccess() {
err := fcmClient.Notify(body, ids...)
s.Require().NoError(err)
s.NoError(err)
}
func (s *FCMProviderTestSuite) TestNotifyError() {
func (s *NotifierTestSuite) TestNotifyError() {
expectedError := errors.New("error")
fcmPayload := getPayload()
ids := []string{"1"}
body := interface{}("body")
@ -65,7 +58,7 @@ func (s *FCMProviderTestSuite) TestNotifyError() {
err := fcmClient.Notify(body, ids...)
s.Require().Equal(expectedError, err)
s.Equal(expectedError, err)
}
func getPayload() *fcm.NotificationPayload {