Basic unit testing for notification service

This commit is contained in:
Eugene 2017-10-09 19:23:09 +03:00 committed by Evgeny Danienko
parent 4aaeeb6ebf
commit acd1c1527c
No known key found for this signature in database
GPG Key ID: BC8C34D8B45BECBF
4 changed files with 197 additions and 0 deletions

View File

@ -135,6 +135,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
test: ##@tests Run unit and integration tests
build/env.sh go test $(UNIT_TEST_PACKAGES)

View File

@ -0,0 +1,118 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: geth/common/notification.go
// Package common is a generated GoMock package.
package common
import (
go_fcm "github.com/NaySoftware/go-fcm"
gomock "github.com/golang/mock/gomock"
reflect "reflect"
)
// MockNotification is a mock of Notification interface
type MockNotification struct {
ctrl *gomock.Controller
recorder *MockNotificationMockRecorder
}
// MockNotificationMockRecorder is the mock recorder for MockNotification
type MockNotificationMockRecorder struct {
mock *MockNotification
}
// NewMockNotification creates a new mock instance
func NewMockNotification(ctrl *gomock.Controller) *MockNotification {
mock := &MockNotification{ctrl: ctrl}
mock.recorder = &MockNotificationMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockNotification) EXPECT() *MockNotificationMockRecorder {
return m.recorder
}
// Notify mocks base method
func (m *MockNotification) Notify(token string) string {
ret := m.ctrl.Call(m, "Notify", token)
ret0, _ := ret[0].(string)
return ret0
}
// Notify indicates an expected call of Notify
func (mr *MockNotificationMockRecorder) Notify(token interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Notify", reflect.TypeOf((*MockNotification)(nil).Notify), token)
}
// Send mocks base method
func (m *MockNotification) Send() error {
ret := m.ctrl.Call(m, "Send")
ret0, _ := ret[0].(error)
return ret0
}
// Send indicates an expected call of Send
func (mr *MockNotificationMockRecorder) Send() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockNotification)(nil).Send))
}
// MockMessaging is a mock of Messaging interface
type MockMessaging struct {
ctrl *gomock.Controller
recorder *MockMessagingMockRecorder
}
// MockMessagingMockRecorder is the mock recorder for MockMessaging
type MockMessagingMockRecorder struct {
mock *MockMessaging
}
// NewMockMessaging creates a new mock instance
func NewMockMessaging(ctrl *gomock.Controller) *MockMessaging {
mock := &MockMessaging{ctrl: ctrl}
mock.recorder = &MockMessagingMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockMessaging) EXPECT() *MockMessagingMockRecorder {
return m.recorder
}
// NewFcmRegIdsMsg mocks base method
func (m *MockMessaging) 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 *MockMessagingMockRecorder) NewFcmRegIdsMsg(list, body interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewFcmRegIdsMsg", reflect.TypeOf((*MockMessaging)(nil).NewFcmRegIdsMsg), list, body)
}
// Send mocks base method
func (m *MockMessaging) 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 *MockMessagingMockRecorder) Send() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockMessaging)(nil).Send))
}
// SetNotificationPayload mocks base method
func (m *MockMessaging) 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 *MockMessagingMockRecorder) SetNotificationPayload(payload interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetNotificationPayload", reflect.TypeOf((*MockMessaging)(nil).SetNotificationPayload), payload)
}

View File

@ -1 +1,23 @@
package notification
import (
"testing"
"github.com/NaySoftware/go-fcm"
t "github.com/status-im/status-go/geth/testing"
"github.com/stretchr/testify/suite"
)
func TestFCMClientTestSuite(t *testing.T) {
suite.Run(t, new(FCMClientTestSuite))
}
type FCMClientTestSuite struct {
t.BaseTestSuite
}
func (s *FCMClientTestSuite) TestNewFCMClient() {
fcmClient := NewFCMClient()
s.Require().NotNil(fcmClient)
s.Require().IsType(&fcm.FcmClient{}, fcmClient)
}

View File

@ -1 +1,57 @@
package notification
import (
"testing"
"github.com/golang/mock/gomock"
"github.com/status-im/status-go/geth/common"
t "github.com/status-im/status-go/geth/testing"
"github.com/stretchr/testify/suite"
)
func TestNotificationTestSuite(t *testing.T) {
suite.Run(t, new(NotificationTestSuite))
}
type NotificationTestSuite struct {
t.BaseTestSuite
messagingMock *common.MockMessaging
messagingMockCtrl *gomock.Controller
}
func (s *NotificationTestSuite) SetupTest() {
s.messagingMockCtrl = gomock.NewController(s.T())
s.messagingMock = common.NewMockMessaging(s.messagingMockCtrl)
}
func (s *NotificationTestSuite) TearDownTest() {
s.messagingMockCtrl.Finish()
}
func (s *NotificationTestSuite) TestNewNotification() {
manager := New(nil)
s.Require().NotNil(manager)
s.Require().IsType(&Manager{}, manager)
}
func (s *NotificationTestSuite) TestNotify() {
token := "test"
s.messagingMock.EXPECT().NewFcmRegIdsMsg([]string{token}, map[string]string{
"msg": "Hello World1",
"sum": "Happy Day",
})
manager := New(s.messagingMock)
res := manager.Notify(token)
s.Require().Equal(token, res)
}
func (s *NotificationTestSuite) TestSend() {
s.messagingMock.EXPECT().Send().Times(1).Return(nil)
manager := New(s.messagingMock)
err := manager.Send()
s.Require().NoError(err)
}