package main import ( "html/template" "io" "log" "testing" "git.sr.ht/~michalr/go-satel" "github.com/stretchr/testify/assert" ) type MockTemplateSender struct { message string s SatelNameGetter } func (self *MockTemplateSender) Send(msg GenericMessage, tpl *template.Template) error { self.message = msg.Format(tpl, self.s, log.New(io.Discard, "", log.Ltime)) return nil } var ( tplMessageTest1 = satel.BasicEventElement{Type: satel.ArmedPartition, Index: 1, Value: true} tplMessageTest2 = satel.BasicEventElement{Type: satel.ZoneViolation, Index: 2, Value: true} ) func TestTelegramTemplate(t *testing.T) { mockSender := MockTemplateSender{s: MockSatelNameGetter{"mockPart"}} tpl, err := template.New("TestTemplate").Parse(TelegramMessageTemplate) assert.NoError(t, err) tgSender := MakeSendToTelegramSync(&mockSender, log.New(io.Discard, "", log.Ltime), tpl) tgSender.Call(GenericMessage{[]satel.BasicEventElement{tplMessageTest1, tplMessageTest2}}) // assert.Equal(t, "siemka", mockSender.message) } func TestIRCTemplate(t *testing.T) { mockSender := MockTemplateSender{s: MockSatelNameGetter{"mockPart"}} tpl, err := template.New("TestTemplate").Parse(IRCMessageTemplate) assert.NoError(t, err) tgSender := MakeSendToTelegramSync(&mockSender, log.New(io.Discard, "", log.Ltime), tpl) tgSender.Call(GenericMessage{[]satel.BasicEventElement{tplMessageTest1, tplMessageTest2}}) // assert.Equal(t, "siemka", mockSender.message) }