0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

Add new optional block tests to setup/templates_test.go

This commit is contained in:
Guilherme Rezende 2015-10-29 20:38:15 -02:00
parent 9d456bba9b
commit a62a7f7cf1

View file

@ -2,8 +2,9 @@ package setup
import ( import (
"fmt" "fmt"
"github.com/mholt/caddy/middleware/templates"
"testing" "testing"
"github.com/mholt/caddy/middleware/templates"
) )
func TestTemplates(t *testing.T) { func TestTemplates(t *testing.T) {
@ -40,7 +41,11 @@ func TestTemplates(t *testing.T) {
if fmt.Sprint(myHandler.Rules[0].IndexFiles) != fmt.Sprint(indexFiles) { if fmt.Sprint(myHandler.Rules[0].IndexFiles) != fmt.Sprint(indexFiles) {
t.Errorf("Expected %v to be the Default Index files", indexFiles) t.Errorf("Expected %v to be the Default Index files", indexFiles)
} }
if myHandler.Rules[0].Delims != [2]string{} {
t.Errorf("Expected %v to be the Default Delims", [2]string{})
}
} }
func TestTemplatesParse(t *testing.T) { func TestTemplatesParse(t *testing.T) {
tests := []struct { tests := []struct {
inputTemplateConfig string inputTemplateConfig string
@ -50,19 +55,32 @@ func TestTemplatesParse(t *testing.T) {
{`templates /api1`, false, []templates.Rule{{ {`templates /api1`, false, []templates.Rule{{
Path: "/api1", Path: "/api1",
Extensions: defaultTemplateExtensions, Extensions: defaultTemplateExtensions,
Delims: [2]string{},
}}}, }}},
{`templates /api2 .txt .htm`, false, []templates.Rule{{ {`templates /api2 .txt .htm`, false, []templates.Rule{{
Path: "/api2", Path: "/api2",
Extensions: []string{".txt", ".htm"}, Extensions: []string{".txt", ".htm"},
Delims: [2]string{},
}}}, }}},
{`templates /api3 .htm .html {`templates /api3 .htm .html
templates /api4 .txt .tpl `, false, []templates.Rule{{ templates /api4 .txt .tpl `, false, []templates.Rule{{
Path: "/api3", Path: "/api3",
Extensions: []string{".htm", ".html"}, Extensions: []string{".htm", ".html"},
Delims: [2]string{},
}, { }, {
Path: "/api4", Path: "/api4",
Extensions: []string{".txt", ".tpl"}, Extensions: []string{".txt", ".tpl"},
Delims: [2]string{},
}}},
{`templates {
path /api5
ext .html
between {% %}
}`, false, []templates.Rule{{
Path: "/api5",
Extensions: []string{".html"},
Delims: [2]string{"{%", "%}"},
}}}, }}},
} }
for i, test := range tests { for i, test := range tests {