36 lines
888 B
Go
36 lines
888 B
Go
package main
|
|
|
|
import (
|
|
"html/template"
|
|
"io"
|
|
"log"
|
|
"testing"
|
|
|
|
"git.sr.ht/~michalr/go-satel"
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type MockTgBotAPI struct {
|
|
callCount int
|
|
}
|
|
|
|
func (self *MockTgBotAPI) Send(c tgbotapi.Chattable) (tgbotapi.Message, error) {
|
|
self.callCount += 1
|
|
return tgbotapi.Message{}, nil
|
|
}
|
|
|
|
var (
|
|
tgSenderMessageTest1 = satel.BasicEventElement{Type: satel.ArmedPartition, Index: 1, Value: true}
|
|
)
|
|
|
|
func TestTelegramSender_NoChatIdsWontSendAnything(t *testing.T) {
|
|
a := assert.New(t)
|
|
tpl := template.Must(template.New("TelegramMessage").Parse(""))
|
|
mockBot := MockTgBotAPI{0}
|
|
|
|
tested := TgSender{&mockBot, MockSatelNameGetter{"mockPart"}, log.New(io.Discard, "", 0), []int64{}}
|
|
tested.Send(GenericMessage{[]satel.BasicEventElement{tgSenderMessageTest1}}, tpl)
|
|
a.Equal(0, mockBot.callCount)
|
|
}
|