-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate_test.go
More file actions
43 lines (39 loc) · 928 Bytes
/
template_test.go
File metadata and controls
43 lines (39 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package httpmatter
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestConvertToGoTemplate(t *testing.T) {
must := require.New(t)
content := `{{who}}
not a {{thing}},
not a {{number}},
not a {{date}}`
out := convertToGoTemplate(content)
must.Equal(`{{ index .Vars "who" }}
not a {{ index .Vars "thing" }},
not a {{ index .Vars "number" }},
not a {{ index .Vars "date" }}`, out)
}
func TestExecuteTemplate(t *testing.T) {
must := require.New(t)
content := `{{ index .Vars "who" }}
not a {{ index .Vars "thing" }}, \r\n
not a {{ index .Vars "number" }},
not a {{ index .Vars "date" }}`
matter := &Matter{
config: Config{},
Vars: map[string]any{
"who": "John",
"thing": "table",
"number": 123,
"date": "2021-01-01",
},
}
out, err := executeTemplate(content, matter)
must.Nil(err)
must.Equal([]byte(`John
not a table, \r\n
not a 123,
not a 2021-01-01`), out)
}