Skip to content

Commit

Permalink
Pick the test improvement out of PR#8371
Browse files Browse the repository at this point in the history
<#8371>

This covers:
  - `tpl` text can `include` a `define` provided in a partial file
  - `tpl` text can `include` a `define` provided in its text
  - `tpl` text can be loaded via `.Files.Get`

Signed-off-by: Graham Reed <greed@7deadly.org>
  • Loading branch information
greed42 committed Oct 20, 2022
1 parent d79ae9f commit d1e9a24
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/engine/engine_test.go
Expand Up @@ -830,3 +830,38 @@ func TestRenderRecursionLimit(t *testing.T) {
}

}

func TestRenderLoadTemplateForTplFromFile(t *testing.T) {
c := &chart.Chart{
Metadata: &chart.Metadata{Name: "TplLoadFromFile"},
Templates: []*chart.File{
{Name: "templates/base", Data: []byte(`{{ tpl (.Files.Get .Values.filename) . }}`)},
{Name: "templates/_function", Data: []byte(`{{define "test-function"}}test-function{{end}}`)},
},
Files: []*chart.File{
{Name: "test", Data: []byte(`{{ tpl (.Files.Get .Values.filename2) .}}`)},
{Name: "test2", Data: []byte(`{{include "test-function" .}}{{define "nested-define"}}nested-define-content{{end}} {{include "nested-define" .}}`)},
},
}

v := chartutil.Values{
"Values": chartutil.Values{
"filename": "test",
"filename2": "test2",
},
"Chart": c.Metadata,
"Release": chartutil.Values{
"Name": "TestRelease",
},
}

out, err := Render(c, v)
if err != nil {
t.Fatal(err)
}

expect := "test-function nested-define-content"
if got := out["TplLoadFromFile/templates/base"]; got != expect {
t.Fatalf("Expected %q, got %q", expect, got)
}
}

0 comments on commit d1e9a24

Please sign in to comment.