Small simplifcation
This commit is contained in:
parent
7a9a973904
commit
1e89fea274
2
main.go
2
main.go
|
@ -45,7 +45,7 @@ func (self TgSender) Send(msg GenericMessage) error {
|
|||
}
|
||||
|
||||
func sendTgMessage(tgEvents chan GenericMessage, msg string, chatId int64) {
|
||||
tgEvents <- GenericMessage{TgChatId{chatId}, []MsgContent{MsgContent{msg}}}
|
||||
tgEvents <- GenericMessage{TgChatId{chatId}, []MsgContent{{msg}}}
|
||||
}
|
||||
|
||||
type RealSleeper struct {
|
||||
|
|
|
@ -37,18 +37,18 @@ func TestMessageThrottling(t *testing.T) {
|
|||
mockSleeper := MockSleeper{nil, 0}
|
||||
Consume(SendToTg(tgSenderWorker(testEvents, &wg, &mockSleeper, log.New(io.Discard, "", log.Ltime)),
|
||||
&mockSender, &wg, log.New(io.Discard, "", log.Ltime)))
|
||||
testEvents <- GenericMessage{TgChatId{123}, []MsgContent{MsgContent{"test1"}}}
|
||||
testEvents <- GenericMessage{TgChatId{124}, []MsgContent{MsgContent{"test3"}}}
|
||||
testEvents <- GenericMessage{TgChatId{123}, []MsgContent{MsgContent{"test2"}}}
|
||||
testEvents <- GenericMessage{TgChatId{124}, []MsgContent{MsgContent{"test4"}}}
|
||||
testEvents <- GenericMessage{TgChatId{123}, []MsgContent{{"test1"}}}
|
||||
testEvents <- GenericMessage{TgChatId{124}, []MsgContent{{"test3"}}}
|
||||
testEvents <- GenericMessage{TgChatId{123}, []MsgContent{{"test2"}}}
|
||||
testEvents <- GenericMessage{TgChatId{124}, []MsgContent{{"test4"}}}
|
||||
assert.Equal(t, 1, mockSleeper.callCount)
|
||||
*mockSleeper.ch <- nil
|
||||
assert.Equal(t, 1, mockSleeper.callCount)
|
||||
testEvents <- GenericMessage{TgChatId{123}, []MsgContent{MsgContent{"test5"}}}
|
||||
testEvents <- GenericMessage{TgChatId{123}, []MsgContent{{"test5"}}}
|
||||
close(testEvents)
|
||||
wg.Wait()
|
||||
assert.Equal(t, 2, mockSleeper.callCount)
|
||||
|
||||
assert.Len(t, mockSender.messages, 3)
|
||||
assert.Contains(t, mockSender.messages, GenericMessage{TgChatId{123}, []MsgContent{MsgContent{"test1"}, MsgContent{"test2"}}})
|
||||
assert.Contains(t, mockSender.messages, GenericMessage{TgChatId{123}, []MsgContent{{"test1"}, {"test2"}}})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue