package main import ( "html/template" "io" "log" "os" "testing" "git.sr.ht/~michalr/go-satel" "github.com/stretchr/testify/assert" ) var ( tgSyncSenderMessageTest1 = satel.BasicEventElement{Type: satel.ArmedPartition, Index: 1, Value: true} ) func TestSyncTelegramSender_NoChatIdsWontSendAnything(t *testing.T) { a := assert.New(t) tpl := template.Must(template.New("TelegramMessage").Parse("")) mockBot := MockTgBotAPI{} s := MockSatelNameGetter{"test_name"} sender := TgSender{&mockBot, s, log.New(io.Discard, "", 0), []int64{}} tested := SendToTelegramSync{SyncFilterImpl{}, &sender, log.New(io.Discard, "", 0), tpl} tested.Call(GenericMessage{[]satel.BasicEventElement{tgSenderMessageTest1}}) a.Equal(0, len(mockBot.messages)) } func TestSyncTelegramSender_SendsMessageToAllChatIds(t *testing.T) { a := assert.New(t) tpl := template.Must(template.New("TelegramMessage").Parse("")) mockBot := MockTgBotAPI{} s := MockSatelNameGetter{"test_name"} sender := TgSender{&mockBot, s, log.New(os.Stderr, "", 0), []int64{1, 2, 3}} tested := SendToTelegramSync{SyncFilterImpl{}, &sender, log.New(os.Stderr, "", 0), tpl} tested.Call(GenericMessage{[]satel.BasicEventElement{tgSenderMessageTest1}}) a.Equal(3, len(mockBot.messages)) }