forked from beego/beego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_test.go
49 lines (46 loc) · 968 Bytes
/
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
package beego
import (
"os"
"path/filepath"
"testing"
)
func TestBuildTemplate(t *testing.T) {
dir := "_beeTmp"
files := []string{
"1.tpl",
"2.html",
"3.htmltpl",
"4.mystyle",
}
if err := os.MkdirAll(dir, 0777); err != nil {
t.Fatal(err)
}
for _, name := range files {
if _, err := os.Create(filepath.Join(dir, name)); err != nil {
t.Fatal(err)
}
}
if err := BuildTemplate(dir); err != nil {
t.Fatal(err)
}
if len(BeeTemplates) != 1 {
t.Fatalf("should be 1 but got %v", len(BeeTemplates))
}
for _, v := range BeeTemplates {
if len(v.Templates()) != 3 {
t.Errorf("should be 3 but got %v", len(v.Templates()))
}
}
AddTemplateExt("mystyle")
if err := BuildTemplate(dir); err != nil {
t.Fatal(err)
}
if len(BeeTemplates) != 1 {
t.Fatalf("should be 1 but got %v", len(BeeTemplates))
}
for _, v := range BeeTemplates {
if len(v.Templates()) != 4 {
t.Errorf("should be 4 but got %v", len(v.Templates()))
}
}
}