Update PN tests
This commit is contained in:
parent
804ed7c10c
commit
c304d3e7ae
1
Makefile
1
Makefile
|
@ -136,6 +136,7 @@ mock-install: ##@other Install mocking tools
|
||||||
mock: ##@other Regenerate mocks
|
mock: ##@other Regenerate mocks
|
||||||
mockgen -source=geth/common/types.go -destination=geth/common/types_mock.go -package=common
|
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/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
|
test: ##@tests Run unit and integration tests
|
||||||
build/env.sh go test $(UNIT_TEST_PACKAGES)
|
build/env.sh go test $(UNIT_TEST_PACKAGES)
|
||||||
|
|
|
@ -5,159 +5,46 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
go_fcm "github.com/NaySoftware/go-fcm"
|
|
||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
message "github.com/status-im/status-go/geth/notification/message"
|
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MockNotification is a mock of Notification interface
|
// MockNotifier is a mock of Notifier interface
|
||||||
type MockNotification struct {
|
type MockNotifier struct {
|
||||||
ctrl *gomock.Controller
|
ctrl *gomock.Controller
|
||||||
recorder *MockNotificationMockRecorder
|
recorder *MockNotifierMockRecorder
|
||||||
}
|
}
|
||||||
|
|
||||||
// MockNotificationMockRecorder is the mock recorder for MockNotification
|
// MockNotifierMockRecorder is the mock recorder for MockNotifier
|
||||||
type MockNotificationMockRecorder struct {
|
type MockNotifierMockRecorder struct {
|
||||||
mock *MockNotification
|
mock *MockNotifier
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMockNotification creates a new mock instance
|
// NewMockNotifier creates a new mock instance
|
||||||
func NewMockNotification(ctrl *gomock.Controller) *MockNotification {
|
func NewMockNotifier(ctrl *gomock.Controller) *MockNotifier {
|
||||||
mock := &MockNotification{ctrl: ctrl}
|
mock := &MockNotifier{ctrl: ctrl}
|
||||||
mock.recorder = &MockNotificationMockRecorder{mock}
|
mock.recorder = &MockNotifierMockRecorder{mock}
|
||||||
return mock
|
return mock
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXPECT returns an object that allows the caller to indicate expected use
|
// 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
|
return m.recorder
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify mocks base method
|
// Notify mocks base method
|
||||||
func (m *MockNotification) Notify(token string, msg *message.Message) (string, error) {
|
func (m *MockNotifier) Notify(body interface{}, tokens ...string) error {
|
||||||
ret := m.ctrl.Call(m, "Notify", token, msg)
|
varargs := []interface{}{body}
|
||||||
ret0, _ := ret[0].(string)
|
for _, a := range tokens {
|
||||||
ret1, _ := ret[1].(error)
|
varargs = append(varargs, a)
|
||||||
return ret0, ret1
|
}
|
||||||
}
|
ret := m.ctrl.Call(m, "Notify", varargs...)
|
||||||
|
|
||||||
// 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")
|
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send indicates an expected call of Send
|
// Notify indicates an expected call of Notify
|
||||||
func (mr *MockMessagingProviderMockRecorder) Send() *gomock.Call {
|
func (mr *MockNotifierMockRecorder) Notify(body interface{}, tokens ...interface{}) *gomock.Call {
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockMessagingProvider)(nil).Send))
|
varargs := append([]interface{}{body}, tokens...)
|
||||||
}
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Notify", reflect.TypeOf((*MockNotifier)(nil).Notify), varargs...)
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
|
@ -11,32 +11,26 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFCMClientTestSuite(t *testing.T) {
|
func TestFCMClientTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(FCMProviderTestSuite))
|
suite.Run(t, new(NotifierTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
type FCMProviderTestSuite struct {
|
type NotifierTestSuite struct {
|
||||||
t.BaseTestSuite
|
t.BaseTestSuite
|
||||||
|
|
||||||
fcmClientMock *MockFirebaseClient
|
fcmClientMock *MockFirebaseClient
|
||||||
fcmClientMockCtrl *gomock.Controller
|
fcmClientMockCtrl *gomock.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FCMProviderTestSuite) SetupTest() {
|
func (s *NotifierTestSuite) SetupTest() {
|
||||||
s.fcmClientMockCtrl = gomock.NewController(s.T())
|
s.fcmClientMockCtrl = gomock.NewController(s.T())
|
||||||
s.fcmClientMock = NewMockFirebaseClient(s.fcmClientMockCtrl)
|
s.fcmClientMock = NewMockFirebaseClient(s.fcmClientMockCtrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FCMProviderTestSuite) TearDownTest() {
|
func (s *NotifierTestSuite) TearDownTest() {
|
||||||
s.fcmClientMockCtrl.Finish()
|
s.fcmClientMockCtrl.Finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FCMProviderTestSuite) TestNewFCMClient() {
|
func (s *NotifierTestSuite) TestNotifySuccess() {
|
||||||
fcmClient := Notifier{s.fcmClientMock}
|
|
||||||
|
|
||||||
s.Require().NotNil(fcmClient)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *FCMProviderTestSuite) TestNotifySuccess() {
|
|
||||||
fcmPayload := getPayload()
|
fcmPayload := getPayload()
|
||||||
ids := []string{"1"}
|
ids := []string{"1"}
|
||||||
body := interface{}("body")
|
body := interface{}("body")
|
||||||
|
@ -48,12 +42,11 @@ func (s *FCMProviderTestSuite) TestNotifySuccess() {
|
||||||
|
|
||||||
err := fcmClient.Notify(body, ids...)
|
err := fcmClient.Notify(body, ids...)
|
||||||
|
|
||||||
s.Require().NoError(err)
|
s.NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FCMProviderTestSuite) TestNotifyError() {
|
func (s *NotifierTestSuite) TestNotifyError() {
|
||||||
expectedError := errors.New("error")
|
expectedError := errors.New("error")
|
||||||
|
|
||||||
fcmPayload := getPayload()
|
fcmPayload := getPayload()
|
||||||
ids := []string{"1"}
|
ids := []string{"1"}
|
||||||
body := interface{}("body")
|
body := interface{}("body")
|
||||||
|
@ -65,7 +58,7 @@ func (s *FCMProviderTestSuite) TestNotifyError() {
|
||||||
|
|
||||||
err := fcmClient.Notify(body, ids...)
|
err := fcmClient.Notify(body, ids...)
|
||||||
|
|
||||||
s.Require().Equal(expectedError, err)
|
s.Equal(expectedError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPayload() *fcm.NotificationPayload {
|
func getPayload() *fcm.NotificationPayload {
|
||||||
|
|
Loading…
Reference in New Issue