-
Notifications
You must be signed in to change notification settings - Fork 43
/
template_test.go
57 lines (45 loc) · 1.13 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package neo
import (
"github.com/stretchr/testify/assert"
"regexp"
"testing"
)
type testWriter struct {
data []byte
}
func (t *testWriter) Write(data []byte) (int, error) {
t.data = append(t.data, data...)
return 0, nil
}
func TestCompileTpl(t *testing.T) {
writer := &testWriter{}
regex := regexp.MustCompile("(?s)<html>.*\n</html>")
// before compiling template, tpl is nil
tpl = nil
err := renderTpl(writer, "testindex", nil)
assert.NotNil(t, err)
writer = &testWriter{}
compileTpl("./testassets/templates/*")
assert.Nil(t, writer.data)
// known template
err = renderTpl(writer, "testindex", nil)
assert.Nil(t, err)
assert.NotNil(t, writer.data)
match := regex.Match(writer.data[:])
assert.True(t, match)
// unknown template
writer.data = nil
err = renderTpl(writer, "unknown", nil)
assert.NotNil(t, err)
match = regex.Match(writer.data[:])
assert.False(t, match)
// wrong path
assert.Panics(t, func() {
compileTpl("./testassets/unknown/**")
})
}
func TestTplExists(t *testing.T) {
assert.False(t, tplExists("testindex"))
compileTpl("./testassets/templates/*")
assert.True(t, tplExists("testindex"))
}