github.com/wuhuizuo/gomplate@v3.5.0+incompatible/tests/integration/nested_templates_test.go (about) 1 //+build integration 2 3 package integration 4 5 import ( 6 . "gopkg.in/check.v1" 7 8 "github.com/gotestyourself/gotestyourself/fs" 9 "github.com/gotestyourself/gotestyourself/icmd" 10 ) 11 12 type NestedTemplatesSuite struct { 13 tmpDir *fs.Dir 14 } 15 16 var _ = Suite(&NestedTemplatesSuite{}) 17 18 func (s *NestedTemplatesSuite) SetUpSuite(c *C) { 19 s.tmpDir = fs.NewDir(c, "gomplate-inttests", 20 fs.WithFile("hello.t", `Hello {{ . }}!`), 21 fs.WithDir("templates", 22 fs.WithFile("one.t", `{{ . }}`), 23 fs.WithFile("two.t", `{{ range $n := (seq 2) }}{{ $n }}: {{ $ }} {{ end }}`), 24 ), 25 ) 26 } 27 28 func (s *NestedTemplatesSuite) TearDownSuite(c *C) { 29 s.tmpDir.Remove() 30 } 31 32 func (s *NestedTemplatesSuite) TestNestedTemplates(c *C) { 33 result := icmd.RunCommand(GomplateBin, 34 "-t", "hello="+s.tmpDir.Join("hello.t"), 35 "-i", `{{ template "hello" "World"}}`, 36 ) 37 result.Assert(c, icmd.Expected{ExitCode: 0, Out: "Hello World!"}) 38 39 result = icmd.RunCmd(icmd.Cmd{ 40 Command: []string{ 41 GomplateBin, 42 "-t", "hello.t", 43 "-i", `{{ template "hello.t" "World"}}`, 44 }, 45 Dir: s.tmpDir.Path(), 46 }, 47 ) 48 result.Assert(c, icmd.Expected{ExitCode: 0, Out: "Hello World!"}) 49 50 result = icmd.RunCmd(icmd.Cmd{ 51 Command: []string{ 52 GomplateBin, 53 "-t", "templates/", 54 "-i", `{{ template "templates/one.t" "one"}} 55 {{ template "templates/two.t" "two"}}`, 56 }, 57 Dir: s.tmpDir.Path(), 58 }, 59 ) 60 result.Assert(c, icmd.Expected{ExitCode: 0, Out: `one 61 1: two 2: two`}) 62 }