From 8c8741591779bd5417e3b96002779288ef93110b Mon Sep 17 00:00:00 2001 From: Geno Date: Wed, 23 Jun 2021 23:18:50 +0200 Subject: [PATCH] test(mailer): templates --- mailer/template_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 mailer/template_test.go diff --git a/mailer/template_test.go b/mailer/template_test.go new file mode 100644 index 0000000..fee3d15 --- /dev/null +++ b/mailer/template_test.go @@ -0,0 +1,39 @@ +package mailer + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestTemplate(t *testing.T) { + assert := assert.New(t) + + value := struct { + T string + }{ + T: "", + } + + templ := TemplateTXT("A {{ .T }") + // invalid template + assert.Nil(templ) + + templ = TemplateTXT("A {{ .T }}") + // text template + assert.Equal("", templ.Render(3)) + + // text template + assert.Equal("A ", templ.Render(&value)) + + templ = TemplateHTML("A {{ .T }") + // invalid template + assert.Nil(templ) + + templ = TemplateHTML("A {{ .T }}") + // html template + assert.Equal("", templ.Render(3)) + + // html template + assert.Equal("A <script>alert('you have been pwned')</script>", templ.Render(&value)) +}