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 integration
import (
"testing"
"gotest.tools/v3/fs"
)
func setupNestedTemplatesTest(t *testing.T) *fs.Dir {
tmpDir := fs.NewDir(t, "gomplate-inttests",
fs.WithFile("hello.t", `Hello {{ . }}!`),
fs.WithDir("templates",
fs.WithFile("one.t", `{{ . }}`),
fs.WithFile("two.t", `{{ range $n := (seq 2) }}{{ $n }}: {{ $ }} {{ end }}`),
),
)
t.Cleanup(tmpDir.Remove)
return tmpDir
}
func TestNestedTemplates(t *testing.T) {
tmpDir := setupNestedTemplatesTest(t)
o, e, err := cmd(t,
"-t", "hello="+tmpDir.Join("hello.t"),
"-i", `{{ template "hello" "World"}}`,
).run()
assertSuccess(t, o, e, err, "Hello World!")
o, e, err = cmd(t, "-t", "hello.t",
"-i", `{{ template "hello.t" "World"}}`).
withDir(tmpDir.Path()).run()
assertSuccess(t, o, e, err, "Hello World!")
o, e, err = cmd(t, "-t", "templates/",
"-i", `{{ template "templates/one.t" "one"}}
{{ template "templates/two.t" "two"}}`).
withDir(tmpDir.Path()).run()
assertSuccess(t, o, e, err, "one\n1: two 2: two ")
// referencing a dir without a trailing / is undocumented, but works
// currently - I don't want to break it...
o, e, err = cmd(t, "-t", "templates",
"-i", `{{ template "templates/one.t" "one"}}
{{ template "templates/two.t" "two"}}`).
withDir(tmpDir.Path()).run()
assertSuccess(t, o, e, err, "one\n1: two 2: two ")
}
|