engine: make template function map public

Signed-off-by: Benjamin Ash <bash@intelerad.com>
pull/8742/head
Benjamin Ash 5 years ago
parent 459dcd7f72
commit c815e0d288

@ -105,7 +105,7 @@ func warnWrap(warn string) string {
// initFunMap creates the Engine's FuncMap and adds context-specific functions.
func (e Engine) initFunMap(t *template.Template, referenceTpls map[string]renderable) {
funcMap := funcMap()
funcMap := FuncMap()
includedNames := make(map[string]int)
// Add the 'include' function here so we can close over t.

@ -61,7 +61,7 @@ func TestSortTemplates(t *testing.T) {
}
func TestFuncMap(t *testing.T) {
fns := funcMap()
fns := FuncMap()
forbidden := []string{"env", "expandenv"}
for _, f := range forbidden {
if _, ok := fns[f]; ok {

@ -27,7 +27,7 @@ import (
"sigs.k8s.io/yaml"
)
// funcMap returns a mapping of all of the functions that Engine has.
// FuncMap returns a mapping of all of the functions that Engine has.
//
// Because some functions are late-bound (e.g. contain context-sensitive
// data), the functions may not all perform identically outside of an Engine
@ -41,7 +41,7 @@ import (
// These are late-bound in Engine.Render(). The
// version included in the FuncMap is a placeholder.
//
func funcMap() template.FuncMap {
func FuncMap() template.FuncMap {
f := sprig.TxtFuncMap()
delete(f, "env")
delete(f, "expandenv")

@ -103,7 +103,7 @@ func TestFuncs(t *testing.T) {
for _, tt := range tests {
var b strings.Builder
err := template.Must(template.New("test").Funcs(funcMap()).Parse(tt.tpl)).Execute(&b, tt.vars)
err := template.Must(template.New("test").Funcs(FuncMap()).Parse(tt.tpl)).Execute(&b, tt.vars)
assert.NoError(t, err)
assert.Equal(t, tt.expect, b.String(), tt.tpl)
}
@ -155,7 +155,7 @@ func TestMerge(t *testing.T) {
}
tpl := `{{merge .dst .src1 .src2}}`
var b strings.Builder
err := template.Must(template.New("test").Funcs(funcMap()).Parse(tpl)).Execute(&b, dict)
err := template.Must(template.New("test").Funcs(FuncMap()).Parse(tpl)).Execute(&b, dict)
assert.NoError(t, err)
expected := map[string]interface{}{

Loading…
Cancel
Save