-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapitpl_test.go
More file actions
69 lines (58 loc) · 1.57 KB
/
apitpl_test.go
File metadata and controls
69 lines (58 loc) · 1.57 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
package apitpl
import (
"bytes"
"html/template"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/apisite/apitpl/lookupfs"
"github.com/apisite/apitpl/samplemeta"
)
type ServerSuite struct {
suite.Suite
cfg lookupfs.Config
srv *TemplateService
}
func TestSuite(t *testing.T) {
myTest := &ServerSuite{}
suite.Run(t, myTest)
}
func (ss *ServerSuite) SetupSuite() {
// BufferPool size for rendered templates
const bufferSize int = 64
ss.cfg = lookupfs.Config{
Layouts: "layouts",
Pages: "pages",
Ext: ".html",
DefLayout: "default",
Root: "testdata",
}
tfs, err := New(bufferSize).
LookupFS(lookupfs.New(ss.cfg)).
ParseAlways(true).
Parse()
require.NoError(ss.T(), err)
ss.srv = tfs
}
func (ss *ServerSuite) TestNoIncludes() {
page := &samplemeta.Meta{}
var b bytes.Buffer
err := ss.srv.Execute(&b, "page", template.FuncMap{}, page)
require.NoError(ss.T(), err)
}
func (ss *ServerSuite) TestPageNotExists() {
page := &samplemeta.Meta{}
page.SetLayout("simple")
var b bytes.Buffer
err := ss.srv.Execute(&b, "page_unknown", template.FuncMap{}, page)
require.NoError(ss.T(), err)
assert.Equal(ss.T(), "<title>Error 0: Sorry</title>\npage page_unknown does not exists\n", b.String())
}
func (ss *ServerSuite) TestLayoutNotExists() {
page := &samplemeta.Meta{}
page.SetLayout("unknown")
var b bytes.Buffer
err := ss.srv.Execute(&b, "page", template.FuncMap{}, page)
assert.Equal(ss.T(), "exec layout: html/template: \"unknown\" is undefined", err.Error())
}