1
0
Fork 0
hswro-alarm-bot/templates_test.go

41 lines
1019 B
Go

package main
import (
"html/template"
"io"
"log"
"sync"
"testing"
"github.com/probakowski/go-satel"
"github.com/stretchr/testify/assert"
)
type MockTemplateSender struct {
message string
}
func (self *MockTemplateSender) Send(msg GenericMessage, tpl *template.Template) error {
self.message = msg.Format(tpl)
return nil
}
var (
tplMessageTest1 = satel.Event{Type: satel.ArmedPartition, Index: 1, Value: true}
tplMessageTest2 = satel.Event{Type: satel.ZoneViolation, Index: 2, Value: true}
)
func TestTelegramTemplate(t *testing.T) {
testEvents := make(chan GenericMessage)
wg := sync.WaitGroup{}
mockSender := MockTemplateSender{}
tpl, err := template.New("TestTemplate").Parse(TelegramMessageTemplate)
assert.NoError(t, err)
Consume(SendToTg(testEvents, &mockSender, &wg, log.New(io.Discard, "", log.Ltime), tpl))
testEvents <- GenericMessage{TgChatId{123}, []MsgContent{{tplMessageTest1}, {tplMessageTest2}}}
close(testEvents)
wg.Wait()
// assert.Equal(t, "siemka", mockSender.message)
}