...
1
9
10 package mailer
11
12 import (
13 "fmt"
14 "testing"
15
16 "gitlab.hexacode.org/go-libs/hctypes"
17 )
18
19 func TestTemplate(t *testing.T) {
20 _, err := NewTemplate("Hello {{ name }}")
21 if err != nil {
22 t.Fatal(err)
23 }
24 }
25
26 func TestTemplateRender(t *testing.T) {
27 tmpl, err := NewTemplate("Hello {{ name['first'] }} {{ name['last'] }}")
28 if err != nil {
29 t.Error(err)
30 }
31 data := hctypes.Dict{
32 "name": hctypes.Dict{
33 "first": "John",
34 "last": "Doe",
35 },
36 }
37 render, err := tmpl.Render(data)
38 if err != nil {
39 t.Error(err)
40 }
41
42 if render != "Hello John Doe" {
43 t.Error(fmt.Errorf("Expected 'Hello John Doe', got '%s'", render))
44 }
45 }
46
View as plain text