This commit is contained in:
Владимир Фёдоров 2023-08-13 21:13:17 +07:00
parent bdc89bea14
commit 6ce7cee5bc
5 changed files with 20 additions and 8 deletions

View File

@ -35,6 +35,18 @@ func (m *MockIStorage) EXPECT() *MockIStorageMockRecorder {
return m.recorder return m.recorder
} }
// Close mocks base method.
func (m *MockIStorage) Close() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Close")
}
// Close indicates an expected call of Close.
func (mr *MockIStorageMockRecorder) Close() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockIStorage)(nil).Close))
}
// GetAllUsersByChatID mocks base method. // GetAllUsersByChatID mocks base method.
func (m *MockIStorage) GetAllUsersByChatID(ctx context.Context, chatID string) ([]storage.User, error) { func (m *MockIStorage) GetAllUsersByChatID(ctx context.Context, chatID string) ([]storage.User, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()

View File

@ -26,7 +26,7 @@ func NewBotAll(
} }
} }
func (bot *botAll) Process(ctx context.Context, msg messenger.Message) error { func (bot *botAll) Process(ctx context.Context, msg *messenger.Message) error {
if err := bot.storage.UpsertUser(ctx, storage.User{ChatID: msg.ChatID, UserID: msg.UserID}); err != nil { if err := bot.storage.UpsertUser(ctx, storage.User{ChatID: msg.ChatID, UserID: msg.UserID}); err != nil {
return err return err
} }

View File

@ -18,7 +18,7 @@ func Test_botAll_Process(t *testing.T) {
name string name string
messenger func(ctrl *gomock.Controller) messenger.IMessenger messenger func(ctrl *gomock.Controller) messenger.IMessenger
storage func(ctrl *gomock.Controller) storage.IStorage storage func(ctrl *gomock.Controller) storage.IStorage
msg messenger.Message msg *messenger.Message
wantErr bool wantErr bool
}{ }{
{ {
@ -34,7 +34,7 @@ func Test_botAll_Process(t *testing.T) {
m.EXPECT().GetAllUsersByChatID(gomock.Any(), gomock.Any()).Times(0) m.EXPECT().GetAllUsersByChatID(gomock.Any(), gomock.Any()).Times(0)
return m return m
}, },
msg: messenger.Message{ msg: &messenger.Message{
ChatID: "123", ChatID: "123",
UserID: "username", UserID: "username",
Text: "hello", Text: "hello",
@ -57,7 +57,7 @@ func Test_botAll_Process(t *testing.T) {
Times(1) Times(1)
return m return m
}, },
msg: messenger.Message{ msg: &messenger.Message{
ChatID: "123", ChatID: "123",
UserID: "username", UserID: "username",
Text: "hello @all", Text: "hello @all",
@ -91,7 +91,7 @@ func Test_botAll_Process(t *testing.T) {
Times(1) Times(1)
return m return m
}, },
msg: messenger.Message{ msg: &messenger.Message{
ChatID: "123", ChatID: "123",
UserID: "username", UserID: "username",
Text: "hello @all", Text: "hello @all",
@ -126,7 +126,7 @@ func Test_botAll_Process(t *testing.T) {
Times(1) Times(1)
return m return m
}, },
msg: messenger.Message{ msg: &messenger.Message{
ChatID: "123", ChatID: "123",
UserID: "username", UserID: "username",
Text: "hello @all", Text: "hello @all",

View File

@ -7,5 +7,5 @@ import (
) )
type IBot interface { type IBot interface {
Process(ctx context.Context, msg messenger.Message) error Process(ctx context.Context, msg *messenger.Message) error
} }

View File

@ -33,7 +33,7 @@ func (s *listenerService) Run(ctx context.Context) error {
} }
return err return err
} }
for b := range s.bots { for _, b := range s.bots {
if err := b.Process(ctx, msg); err != nil { if err := b.Process(ctx, msg); err != nil {
log.Println(err) log.Println(err)
} }