From a8adc10bd364cb4130403818eb691d21da5f94de Mon Sep 17 00:00:00 2001 From: Kleonikos Kyriakis Date: Fri, 26 Apr 2024 10:30:09 +0300 Subject: [PATCH] more tests & refactorings --- internal/app/app.go | 6 +- internal/messaging/mock_list_grpc.pb.go | 62 ++++++++ internal/messaging/mock_messenger.go | 111 +++++++++++++ internal/messaging/mock_service_registry.go | 68 ++++++++ internal/messaging/noop_response_handler.go | 2 +- internal/messaging/processor.go | 12 +- internal/messaging/processor_test.go | 164 ++++++++++++++++++++ internal/messaging/service.go | 4 +- internal/messaging/service_registry.go | 16 +- internal/rpc/server/server.go | 6 +- scripts/mocks.mockgen.txt | 4 + 11 files changed, 432 insertions(+), 23 deletions(-) create mode 100644 internal/messaging/mock_list_grpc.pb.go create mode 100644 internal/messaging/mock_messenger.go create mode 100644 internal/messaging/mock_service_registry.go create mode 100644 internal/messaging/processor_test.go diff --git a/internal/app/app.go b/internal/app/app.go index 259d3f16..8fded156 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -49,7 +49,7 @@ func (a *App) Run(ctx context.Context) error { serviceRegistry := messaging.NewServiceRegistry(a.logger) // start rpc client if host is provided, otherwise bot serves as a distributor bot (rpc server) if a.cfg.PartnerPluginConfig.Host != "" { - a.startRPCClient(gCtx, g, *serviceRegistry) + a.startRPCClient(gCtx, g, serviceRegistry) } else { a.logger.Infof("No host for partner plugin provided, bot will serve as a distributor bot.") serviceRegistry.RegisterServices(a.cfg.SupportedRequestTypes, nil) @@ -122,7 +122,7 @@ func (a *App) startMessenger(ctx context.Context, g *errgroup.Group) (messaging. return messenger, userIDUpdatedChan } -func (a *App) startRPCServer(ctx context.Context, msgProcessor messaging.Processor, serviceRegistry *messaging.ServiceRegistry, g *errgroup.Group) { +func (a *App) startRPCServer(ctx context.Context, msgProcessor messaging.Processor, serviceRegistry messaging.ServiceRegistry, g *errgroup.Group) { rpcServer := server.NewServer(&a.cfg.RPCServerConfig, a.logger, msgProcessor, serviceRegistry) g.Go(func() error { a.logger.Info("Starting gRPC server...") @@ -135,7 +135,7 @@ func (a *App) startRPCServer(ctx context.Context, msgProcessor messaging.Process }) } -func (a *App) startMessageProcessor(ctx context.Context, messenger messaging.Messenger, serviceRegistry *messaging.ServiceRegistry, responseHandler messaging.ResponseHandler, g *errgroup.Group, userIDUpdated chan string) messaging.Processor { +func (a *App) startMessageProcessor(ctx context.Context, messenger messaging.Messenger, serviceRegistry messaging.ServiceRegistry, responseHandler messaging.ResponseHandler, g *errgroup.Group, userIDUpdated chan string) messaging.Processor { msgProcessor := messaging.NewProcessor(messenger, a.logger, a.cfg.ProcessorConfig, serviceRegistry, responseHandler) g.Go(func() error { // Wait for userID to be passed diff --git a/internal/messaging/mock_list_grpc.pb.go b/internal/messaging/mock_list_grpc.pb.go new file mode 100644 index 00000000..c7b77eb3 --- /dev/null +++ b/internal/messaging/mock_list_grpc.pb.go @@ -0,0 +1,62 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: buf.build/gen/go/chain4travel/camino-messenger-protocol/grpc/go/cmp/services/activity/v1alpha/activityv1alphagrpc (interfaces: ActivityProductListServiceClient) +// +// Generated by this command: +// +// mockgen -package=messaging -destination=internal/messaging/mock_list_grpc.pb.go buf.build/gen/go/chain4travel/camino-messenger-protocol/grpc/go/cmp/services/activity/v1alpha/activityv1alphagrpc ActivityProductListServiceClient +// + +// Package messaging is a generated GoMock package. +package messaging + +import ( + context "context" + reflect "reflect" + + activityv1alpha "buf.build/gen/go/chain4travel/camino-messenger-protocol/protocolbuffers/go/cmp/services/activity/v1alpha" + gomock "go.uber.org/mock/gomock" + grpc "google.golang.org/grpc" +) + +// MockActivityProductListServiceClient is a mock of ActivityProductListServiceClient interface. +type MockActivityProductListServiceClient struct { + ctrl *gomock.Controller + recorder *MockActivityProductListServiceClientMockRecorder +} + +// MockActivityProductListServiceClientMockRecorder is the mock recorder for MockActivityProductListServiceClient. +type MockActivityProductListServiceClientMockRecorder struct { + mock *MockActivityProductListServiceClient +} + +// NewMockActivityProductListServiceClient creates a new mock instance. +func NewMockActivityProductListServiceClient(ctrl *gomock.Controller) *MockActivityProductListServiceClient { + mock := &MockActivityProductListServiceClient{ctrl: ctrl} + mock.recorder = &MockActivityProductListServiceClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockActivityProductListServiceClient) EXPECT() *MockActivityProductListServiceClientMockRecorder { + return m.recorder +} + +// ActivityProductList mocks base method. +func (m *MockActivityProductListServiceClient) ActivityProductList(arg0 context.Context, arg1 *activityv1alpha.ActivityProductListRequest, arg2 ...grpc.CallOption) (*activityv1alpha.ActivityProductListResponse, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ActivityProductList", varargs...) + ret0, _ := ret[0].(*activityv1alpha.ActivityProductListResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ActivityProductList indicates an expected call of ActivityProductList. +func (mr *MockActivityProductListServiceClientMockRecorder) ActivityProductList(arg0, arg1 any, arg2 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ActivityProductList", reflect.TypeOf((*MockActivityProductListServiceClient)(nil).ActivityProductList), varargs...) +} diff --git a/internal/messaging/mock_messenger.go b/internal/messaging/mock_messenger.go new file mode 100644 index 00000000..126f9941 --- /dev/null +++ b/internal/messaging/mock_messenger.go @@ -0,0 +1,111 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/chain4travel/camino-messenger-bot/internal/messaging (interfaces: Messenger) +// +// Generated by this command: +// +// mockgen -package=messaging -destination=internal/messaging/mock_messenger.go github.com/chain4travel/camino-messenger-bot/internal/messaging Messenger +// + +// Package messaging is a generated GoMock package. +package messaging + +import ( + context "context" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" +) + +// MockMessenger is a mock of Messenger interface. +type MockMessenger struct { + ctrl *gomock.Controller + recorder *MockMessengerMockRecorder +} + +// MockMessengerMockRecorder is the mock recorder for MockMessenger. +type MockMessengerMockRecorder struct { + mock *MockMessenger +} + +// NewMockMessenger creates a new mock instance. +func NewMockMessenger(ctrl *gomock.Controller) *MockMessenger { + mock := &MockMessenger{ctrl: ctrl} + mock.recorder = &MockMessengerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockMessenger) EXPECT() *MockMessengerMockRecorder { + return m.recorder +} + +// Checkpoint mocks base method. +func (m *MockMessenger) Checkpoint() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Checkpoint") + ret0, _ := ret[0].(string) + return ret0 +} + +// Checkpoint indicates an expected call of Checkpoint. +func (mr *MockMessengerMockRecorder) Checkpoint() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Checkpoint", reflect.TypeOf((*MockMessenger)(nil).Checkpoint)) +} + +// Inbound mocks base method. +func (m *MockMessenger) Inbound() chan Message { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Inbound") + ret0, _ := ret[0].(chan Message) + return ret0 +} + +// Inbound indicates an expected call of Inbound. +func (mr *MockMessengerMockRecorder) Inbound() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Inbound", reflect.TypeOf((*MockMessenger)(nil).Inbound)) +} + +// SendAsync mocks base method. +func (m *MockMessenger) SendAsync(arg0 context.Context, arg1 Message) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendAsync", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendAsync indicates an expected call of SendAsync. +func (mr *MockMessengerMockRecorder) SendAsync(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendAsync", reflect.TypeOf((*MockMessenger)(nil).SendAsync), arg0, arg1) +} + +// StartReceiver mocks base method. +func (m *MockMessenger) StartReceiver() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StartReceiver") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StartReceiver indicates an expected call of StartReceiver. +func (mr *MockMessengerMockRecorder) StartReceiver() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartReceiver", reflect.TypeOf((*MockMessenger)(nil).StartReceiver)) +} + +// StopReceiver mocks base method. +func (m *MockMessenger) StopReceiver() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StopReceiver") + ret0, _ := ret[0].(error) + return ret0 +} + +// StopReceiver indicates an expected call of StopReceiver. +func (mr *MockMessengerMockRecorder) StopReceiver() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StopReceiver", reflect.TypeOf((*MockMessenger)(nil).StopReceiver)) +} diff --git a/internal/messaging/mock_service_registry.go b/internal/messaging/mock_service_registry.go new file mode 100644 index 00000000..24e8f0d2 --- /dev/null +++ b/internal/messaging/mock_service_registry.go @@ -0,0 +1,68 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/chain4travel/camino-messenger-bot/internal/messaging (interfaces: ServiceRegistry) +// +// Generated by this command: +// +// mockgen -package=messaging -destination=internal/messaging/mock_service_registry.go github.com/chain4travel/camino-messenger-bot/internal/messaging ServiceRegistry +// + +// Package messaging is a generated GoMock package. +package messaging + +import ( + reflect "reflect" + + config "github.com/chain4travel/camino-messenger-bot/config" + client "github.com/chain4travel/camino-messenger-bot/internal/rpc/client" + gomock "go.uber.org/mock/gomock" +) + +// MockServiceRegistry is a mock of ServiceRegistry interface. +type MockServiceRegistry struct { + ctrl *gomock.Controller + recorder *MockServiceRegistryMockRecorder +} + +// MockServiceRegistryMockRecorder is the mock recorder for MockServiceRegistry. +type MockServiceRegistryMockRecorder struct { + mock *MockServiceRegistry +} + +// NewMockServiceRegistry creates a new mock instance. +func NewMockServiceRegistry(ctrl *gomock.Controller) *MockServiceRegistry { + mock := &MockServiceRegistry{ctrl: ctrl} + mock.recorder = &MockServiceRegistryMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockServiceRegistry) EXPECT() *MockServiceRegistryMockRecorder { + return m.recorder +} + +// GetService mocks base method. +func (m *MockServiceRegistry) GetService(arg0 MessageType) (Service, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetService", arg0) + ret0, _ := ret[0].(Service) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetService indicates an expected call of GetService. +func (mr *MockServiceRegistryMockRecorder) GetService(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetService", reflect.TypeOf((*MockServiceRegistry)(nil).GetService), arg0) +} + +// RegisterServices mocks base method. +func (m *MockServiceRegistry) RegisterServices(arg0 config.SupportedRequestTypesFlag, arg1 *client.RPCClient) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterServices", arg0, arg1) +} + +// RegisterServices indicates an expected call of RegisterServices. +func (mr *MockServiceRegistryMockRecorder) RegisterServices(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockServiceRegistry)(nil).RegisterServices), arg0, arg1) +} diff --git a/internal/messaging/noop_response_handler.go b/internal/messaging/noop_response_handler.go index f250355d..4967dfde 100644 --- a/internal/messaging/noop_response_handler.go +++ b/internal/messaging/noop_response_handler.go @@ -13,5 +13,5 @@ var _ ResponseHandler = (*NoopResponseHandler)(nil) type NoopResponseHandler struct{} -func (n NoopResponseHandler) HandleResponse(context.Context, MessageType, *RequestContent, *ResponseContent) { +func (NoopResponseHandler) HandleResponse(context.Context, MessageType, *RequestContent, *ResponseContent) { } diff --git a/internal/messaging/processor.go b/internal/messaging/processor.go index e184cc63..0df25b74 100644 --- a/internal/messaging/processor.go +++ b/internal/messaging/processor.go @@ -14,10 +14,6 @@ import ( grpc_metadata "google.golang.org/grpc/metadata" ) -type InvalidMessageError struct { - error -} - var ( _ Processor = (*processor)(nil) @@ -51,7 +47,7 @@ type processor struct { mu sync.Mutex responseChannels map[string]chan *Message - serviceRegistry *ServiceRegistry + serviceRegistry ServiceRegistry responseHandler ResponseHandler } @@ -63,7 +59,7 @@ func (p *processor) Checkpoint() string { return "processor" } -func NewProcessor(messenger Messenger, logger *zap.SugaredLogger, cfg config.ProcessorConfig, registry *ServiceRegistry, responseHandler ResponseHandler) Processor { +func NewProcessor(messenger Messenger, logger *zap.SugaredLogger, cfg config.ProcessorConfig, registry ServiceRegistry, responseHandler ResponseHandler) Processor { return &processor{ cfg: cfg, messenger: messenger, @@ -105,7 +101,7 @@ func (p *processor) ProcessInbound(msg *Message) error { p.Forward(msg) return nil default: - return InvalidMessageError{ErrUnknownMessageCategory} + return ErrUnknownMessageCategory } } else { return nil // ignore own outbound messages @@ -198,10 +194,10 @@ func (p *processor) Respond(msg *Message) error { func (p *processor) Forward(msg *Message) { p.logger.Debugf("Forwarding outbound response message: %s", msg.Metadata.RequestID) p.mu.Lock() + defer p.mu.Unlock() responseChan, ok := p.responseChannels[msg.Metadata.RequestID] if ok { responseChan <- msg close(responseChan) } - p.mu.Unlock() } diff --git a/internal/messaging/processor_test.go b/internal/messaging/processor_test.go new file mode 100644 index 00000000..0d161ffa --- /dev/null +++ b/internal/messaging/processor_test.go @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2024, Chain4Travel AG. All rights reserved. + * See the file LICENSE for licensing terms. + */ + +package messaging + +import ( + "errors" + "testing" + + "go.uber.org/mock/gomock" + + "github.com/chain4travel/camino-messenger-bot/internal/metadata" + + "github.com/stretchr/testify/require" + + "github.com/chain4travel/camino-messenger-bot/config" + "go.uber.org/zap" +) + +func TestProcessInbound(t *testing.T) { + userID := "userID" + anotherUserID := "anotherUserID" + someError := errors.New("some error") + requestID := "requestID" + responseMessage := Message{Type: ActivityProductListResponse, Metadata: metadata.Metadata{RequestID: requestID, Sender: anotherUserID}} + + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + mockServiceRegistry := NewMockServiceRegistry(mockCtrl) + mockActivityProductListServiceClient := NewMockActivityProductListServiceClient(mockCtrl) + mockMessenger := NewMockMessenger(mockCtrl) + + type fields struct { + cfg config.ProcessorConfig + messenger Messenger + serviceRegistry ServiceRegistry + responseHandler ResponseHandler + } + type args struct { + msg *Message + } + tests := map[string]struct { + fields fields + args args + prepare func(p *processor) + err error + assert func(t *testing.T, p *processor) + }{ + "err: user id not set": { + fields: fields{ + cfg: config.ProcessorConfig{}, + }, + err: ErrUserIDNotSet, + }, + "err: invalid message type": { + fields: fields{ + cfg: config.ProcessorConfig{}, + }, + prepare: func(p *processor) { + p.SetUserID(userID) + }, + args: args{ + msg: &Message{Type: "invalid", Metadata: metadata.Metadata{Sender: anotherUserID}}, + }, + err: ErrUnknownMessageCategory, + }, + "err: unsupported request message": { + fields: fields{ + cfg: config.ProcessorConfig{}, + serviceRegistry: mockServiceRegistry, + }, + prepare: func(p *processor) { + p.SetUserID(userID) + mockServiceRegistry.EXPECT().GetService(gomock.Any()).Return(nil, false) + }, + args: args{ + msg: &Message{Type: ActivitySearchRequest, Metadata: metadata.Metadata{Sender: anotherUserID}}, + }, + err: ErrUnsupportedRequestType, + }, + "ignore own outbound messages": { + fields: fields{ + cfg: config.ProcessorConfig{}, + }, + prepare: func(p *processor) { + p.SetUserID(userID) + }, + args: args{ + msg: &Message{Metadata: metadata.Metadata{Sender: userID}}, + }, + err: nil, // no error, msg will be just ignored + }, + "err: process request message failed": { + fields: fields{ + cfg: config.ProcessorConfig{}, + serviceRegistry: mockServiceRegistry, + responseHandler: NoopResponseHandler{}, + messenger: mockMessenger, + }, + prepare: func(p *processor) { + p.SetUserID(userID) + mockActivityProductListServiceClient.EXPECT().ActivityProductList(gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil, nil) + mockServiceRegistry.EXPECT().GetService(gomock.Any()).Times(1).Return(activityProductListService{client: mockActivityProductListServiceClient}, true) + mockMessenger.EXPECT().SendAsync(gomock.Any(), gomock.Any()).Times(1).Return(someError) + }, + args: args{ + msg: &Message{Type: ActivityProductListRequest, Metadata: metadata.Metadata{Sender: anotherUserID}}, + }, + err: someError, + }, + "success: process request message": { + fields: fields{ + cfg: config.ProcessorConfig{}, + serviceRegistry: mockServiceRegistry, + responseHandler: NoopResponseHandler{}, + messenger: mockMessenger, + }, + prepare: func(p *processor) { + p.SetUserID(userID) + mockActivityProductListServiceClient.EXPECT().ActivityProductList(gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil, nil) + mockServiceRegistry.EXPECT().GetService(gomock.Any()).Times(1).Return(activityProductListService{client: mockActivityProductListServiceClient}, true) + mockMessenger.EXPECT().SendAsync(gomock.Any(), gomock.Any()).Times(1).Return(nil) + }, + args: args{ + msg: &Message{Type: ActivityProductListRequest, Metadata: metadata.Metadata{Sender: anotherUserID}}, + }, + }, + "success: process response message": { + fields: fields{ + cfg: config.ProcessorConfig{}, + serviceRegistry: mockServiceRegistry, + responseHandler: NoopResponseHandler{}, + messenger: mockMessenger, + }, + prepare: func(p *processor) { + p.responseChannels[requestID] = make(chan *Message, 1) + p.SetUserID(userID) + }, + args: args{ + msg: &responseMessage, + }, + assert: func(t *testing.T, p *processor) { + msgReceived := <-p.responseChannels[requestID] + require.Equal(t, responseMessage, *msgReceived) + }, + }, + } + for tc, tt := range tests { + t.Run(tc, func(t *testing.T) { + p := NewProcessor(tt.fields.messenger, zap.NewNop().Sugar(), tt.fields.cfg, tt.fields.serviceRegistry, tt.fields.responseHandler) + if tt.prepare != nil { + tt.prepare(p.(*processor)) + } + err := p.ProcessInbound(tt.args.msg) + require.ErrorIs(t, err, tt.err) + + if tt.assert != nil { + tt.assert(t, p.(*processor)) + } + }) + } +} diff --git a/internal/messaging/service.go b/internal/messaging/service.go index fa7b1ee8..04abaf8a 100644 --- a/internal/messaging/service.go +++ b/internal/messaging/service.go @@ -40,11 +40,11 @@ type Service interface { Call(ctx context.Context, request *RequestContent, opts ...grpc.CallOption) (*ResponseContent, MessageType, error) } type activityProductListService struct { - client *activityv1alphagrpc.ActivityProductListServiceClient + client activityv1alphagrpc.ActivityProductListServiceClient } func (a activityProductListService) Call(ctx context.Context, request *RequestContent, opts ...grpc.CallOption) (*ResponseContent, MessageType, error) { - response, err := (*a.client).ActivityProductList(ctx, request.ActivityProductListRequest, opts...) + response, err := a.client.ActivityProductList(ctx, request.ActivityProductListRequest, opts...) responseContent := ResponseContent{} if err == nil { responseContent.ActivityProductListResponse = response // otherwise nil pointer dereference diff --git a/internal/messaging/service_registry.go b/internal/messaging/service_registry.go index 84be0c28..bd0b7c79 100644 --- a/internal/messaging/service_registry.go +++ b/internal/messaging/service_registry.go @@ -17,21 +17,25 @@ import ( "go.uber.org/zap" ) -type ServiceRegistry struct { +type ServiceRegistry interface { + RegisterServices(requestTypes config.SupportedRequestTypesFlag, rpcClient *client.RPCClient) + GetService(messageType MessageType) (Service, bool) +} +type serviceRegistry struct { logger *zap.SugaredLogger services map[MessageType]Service lock *sync.RWMutex } -func NewServiceRegistry(logger *zap.SugaredLogger) *ServiceRegistry { - return &ServiceRegistry{ +func NewServiceRegistry(logger *zap.SugaredLogger) ServiceRegistry { + return &serviceRegistry{ logger: logger, services: make(map[MessageType]Service), lock: &sync.RWMutex{}, } } -func (s *ServiceRegistry) RegisterServices(requestTypes config.SupportedRequestTypesFlag, rpcClient *client.RPCClient) { +func (s *serviceRegistry) RegisterServices(requestTypes config.SupportedRequestTypesFlag, rpcClient *client.RPCClient) { s.lock.Lock() defer s.lock.Unlock() @@ -40,7 +44,7 @@ func (s *ServiceRegistry) RegisterServices(requestTypes config.SupportedRequestT switch MessageType(requestType) { case ActivityProductListRequest: c := activityv1alphagrpc.NewActivityProductListServiceClient(rpcClient.ClientConn) - service = activityProductListService{client: &c} + service = activityProductListService{client: c} case ActivitySearchRequest: c := activityv1alphagrpc.NewActivitySearchServiceClient(rpcClient.ClientConn) service = activityService{client: &c} @@ -76,7 +80,7 @@ func (s *ServiceRegistry) RegisterServices(requestTypes config.SupportedRequestT } } -func (s *ServiceRegistry) GetService(messageType MessageType) (Service, bool) { +func (s *serviceRegistry) GetService(messageType MessageType) (Service, bool) { service, ok := s.services[messageType] return service, ok } diff --git a/internal/rpc/server/server.go b/internal/rpc/server/server.go index 1da08bef..4d9ffc1a 100644 --- a/internal/rpc/server/server.go +++ b/internal/rpc/server/server.go @@ -56,14 +56,14 @@ type server struct { cfg *config.RPCServerConfig logger *zap.SugaredLogger processor messaging.Processor - serviceRegistry *messaging.ServiceRegistry + serviceRegistry messaging.ServiceRegistry } -func (s *server) Checkpoint() string { +func (*server) Checkpoint() string { return "request-gateway" } -func NewServer(cfg *config.RPCServerConfig, logger *zap.SugaredLogger, processor messaging.Processor, serviceRegistry *messaging.ServiceRegistry) Server { +func NewServer(cfg *config.RPCServerConfig, logger *zap.SugaredLogger, processor messaging.Processor, serviceRegistry messaging.ServiceRegistry) Server { var opts []grpc.ServerOption if cfg.Unencrypted { logger.Warn("Running gRPC server without TLS!") diff --git a/scripts/mocks.mockgen.txt b/scripts/mocks.mockgen.txt index 92a95658..733f461b 100644 --- a/scripts/mocks.mockgen.txt +++ b/scripts/mocks.mockgen.txt @@ -1,2 +1,6 @@ github.com/chain4travel/camino-messenger-bot/internal/compression=Decompressor=internal/compression/mock_decompress.go github.com/chain4travel/camino-messenger-bot/internal/matrix=Client=internal/matrix/mock_room_handler.go +buf.build/gen/go/chain4travel/camino-messenger-protocol/grpc/go/cmp/services/activity/v1alpha/activityv1alphagrpc=ActivityProductListServiceClient=internal/messaging/mock_list_grpc.pb.go +github.com/chain4travel/camino-messenger-bot/internal/messaging=ServiceRegistry=internal/messaging/mock_service_registry.go +github.com/chain4travel/camino-messenger-bot/internal/messaging=Messenger=internal/messaging/mock_messenger.go +