From 2a9852fa9408d69b8f2f82e78dda81eb189f5827 Mon Sep 17 00:00:00 2001 From: miraclesu Date: Thu, 1 Aug 2013 12:10:56 +0800 Subject: [PATCH] Add template test --- template_test.go | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 template_test.go diff --git a/template_test.go b/template_test.go new file mode 100644 index 00000000..01ac0040 --- /dev/null +++ b/template_test.go @@ -0,0 +1,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())) + } + } +}