pull/13497/merge
V02460 2 weeks ago committed by GitHub
commit 647c362c22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -156,7 +156,7 @@ func includeFun(t *template.Template, includedNames map[string]int) func(string,
}
err := t.ExecuteTemplate(&buf, name, data)
includedNames[name]--
return buf.String(), err
return strings.ReplaceAll(buf.String(), "<no value>", ""), err
}
}

@ -1429,3 +1429,42 @@ func TestRenderCustomTemplateFuncs(t *testing.T) {
t.Errorf("Expected %q, got %q", expected, rendered)
}
}
func TestRenderNilValue(t *testing.T) {
chart := &chart.Chart{
Metadata: &chart.Metadata{
Name: "moby",
Version: "1.2.3",
},
Templates: []*chart.File{
{Name: "templates/_helpers.tpl", Data: []byte(`` +
`{{- define "noval" -}}{{ and nil }}{{- end -}}` +
`{{- define "noval_str" -}}<no value>{{- end -}}`)},
{Name: "templates/test_include.yaml", Data: []byte(`{{ eq (include "noval" .) "" }}`)},
{Name: "templates/test_tpl.yaml", Data: []byte(`{{ eq (tpl "{{ and nil }}" .) "" }}`)},
{Name: "templates/test_render.yaml", Data: []byte(`{{ and nil }}`)},
{Name: "templates/test_include_str.yaml", Data: []byte(`{{ eq (include "noval_str" .) "<no value>" }}`)},
{Name: "templates/test_tpl_str.yaml", Data: []byte(`{{ eq (tpl "<no value>" .) "<no value>" }}`)},
{Name: "templates/test_render_str.yaml", Data: []byte(`<no value>`)},
},
}
out, err := Render(chart, chartutil.Values{})
if err != nil {
t.Fatalf("Failed to render templates: %s", err)
}
expect := map[string]string{
"moby/templates/test_include.yaml": "true",
"moby/templates/test_tpl.yaml": "true",
"moby/templates/test_render.yaml": "",
"moby/templates/test_include_str.yaml": "true",
"moby/templates/test_tpl_str.yaml": "true",
"moby/templates/test_render_str.yaml": "<no value>",
}
for name, data := range expect {
if out[name] != data {
t.Fatalf("Expected %q, got %q (%q)", data, out[name], name)
}
}
}

Loading…
Cancel
Save