mirror of
https://github.com/caddyserver/caddy.git
synced 2025-06-24 01:41:22 +08:00
templates: Add arguments to .Include
This commit is contained in:
@ -30,6 +30,7 @@ func TestInclude(t *testing.T) {
|
||||
}()
|
||||
|
||||
tests := []struct {
|
||||
args []interface{}
|
||||
fileContent string
|
||||
expectedContent string
|
||||
shouldErr bool
|
||||
@ -42,7 +43,15 @@ func TestInclude(t *testing.T) {
|
||||
shouldErr: false,
|
||||
expectedErrorContent: "",
|
||||
},
|
||||
// Test 1 - failure on template.Parse
|
||||
// Test 1 - all good, with args
|
||||
{
|
||||
args: []interface{}{"hello", 5},
|
||||
fileContent: `str1 {{ .Root }} str2 {{index .Args 0}} {{index .Args 1}}`,
|
||||
expectedContent: fmt.Sprintf("str1 %s str2 %s %d", context.Root, "hello", 5),
|
||||
shouldErr: false,
|
||||
expectedErrorContent: "",
|
||||
},
|
||||
// Test 2 - failure on template.Parse
|
||||
{
|
||||
fileContent: `str1 {{ .Root } str2`,
|
||||
expectedContent: "",
|
||||
@ -73,7 +82,7 @@ func TestInclude(t *testing.T) {
|
||||
t.Fatal(testPrefix+"Failed to create test file. Error was: %v", err)
|
||||
}
|
||||
|
||||
content, err := context.Include(inputFilename)
|
||||
content, err := context.Include(inputFilename, test.args...)
|
||||
if err != nil {
|
||||
if !test.shouldErr {
|
||||
t.Errorf(testPrefix+"Expected no error, found [%s]", test.expectedErrorContent, err.Error())
|
||||
|
Reference in New Issue
Block a user