-
-
Notifications
You must be signed in to change notification settings - Fork 930
/
load_template_test.go
36 lines (29 loc) · 977 Bytes
/
load_template_test.go
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
package template
import (
"bytes"
"os"
"path/filepath"
"testing"
"github.com/shurcooL/go/ioutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/ory/kratos/x"
)
func TestLoadTextTemplate(t *testing.T) {
var executeTemplate = func(t *testing.T, path string) string {
tp, err := loadTextTemplate(path, nil)
require.NoError(t, err)
return tp
}
t.Run("method=from bundled", func(t *testing.T) {
actual := executeTemplate(t, "/courier/template/templates/test_stub/email.body.gotmpl")
assert.Contains(t, actual, "stub email")
})
t.Run("method=cache works", func(t *testing.T) {
fp := filepath.Join(os.TempDir(), x.NewUUID().String()) + ".body.gotmpl"
require.NoError(t, ioutil.WriteFile(fp, bytes.NewBufferString("cached stub body")))
assert.Contains(t, executeTemplate(t, fp), "cached stub body")
require.NoError(t, os.RemoveAll(fp))
assert.Contains(t, executeTemplate(t, fp), "cached stub body")
})
}