forked from gobuffalo/buffalo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplain_test.go
46 lines (37 loc) · 991 Bytes
/
plain_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
37
38
39
40
41
42
43
44
45
46
package render_test
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/packr"
"github.com/stretchr/testify/require"
)
func Test_Plain(t *testing.T) {
r := require.New(t)
tDir, err := ioutil.TempDir("", "templates")
if err != nil {
r.Fail("Could not set the templates dir")
}
tmpFile, err := os.Create(filepath.Join(tDir, "test"))
r.NoError(err)
defer os.Remove(tmpFile.Name())
_, err = tmpFile.Write([]byte("<%= name %>"))
r.NoError(err)
type ji func(...string) render.Renderer
j := render.New(render.Options{
TemplatesBox: packr.NewBox(tDir),
}).Plain
re := j(filepath.Base(tmpFile.Name()))
r.Equal("text/plain; charset=utf-8", re.ContentType())
var examples = []string{"Mark", "Jém"}
for _, example := range examples {
example := example
bb := &bytes.Buffer{}
err := re.Render(bb, map[string]interface{}{"name": example})
r.NoError(err)
r.Equal(example, bb.String())
}
}