mirror of
https://github.com/wahyd4/caddy.git
synced 2026-08-22 19:56:31 +10:00
template: add test for custom function
Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
@@ -264,8 +264,7 @@ func ContextInclude(filename string, ctx interface{}, fs http.FileSystem) (strin
|
||||
return "", err
|
||||
}
|
||||
|
||||
tpl := template.New(filename).Funcs(TemplateFuncs)
|
||||
tpl, err = tpl.Parse(string(body))
|
||||
tpl, err := template.New(filename).Funcs(TemplateFuncs).Parse(string(body))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -72,8 +72,16 @@ func TestInclude(t *testing.T) {
|
||||
shouldErr: true,
|
||||
expectedErrorContent: `type httpserver.Context`,
|
||||
},
|
||||
// Test 4 - all good, with custom function
|
||||
{
|
||||
fileContent: `hello {{ caddy }}`,
|
||||
expectedContent: "hello caddy",
|
||||
shouldErr: false,
|
||||
expectedErrorContent: "",
|
||||
},
|
||||
}
|
||||
|
||||
TemplateFuncs["caddy"] = func() string { return "caddy" }
|
||||
for i, test := range tests {
|
||||
testPrefix := getTestPrefix(i)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user