mirror of https://github.com/helm/helm
parent
180bc7da05
commit
5efc021978
@ -0,0 +1,26 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"io"
|
||||
"text/template"
|
||||
|
||||
"github.com/Masterminds/sprig"
|
||||
"github.com/kubernetes/deployment-manager/log"
|
||||
)
|
||||
|
||||
// Render renders a template and values into an output stream.
|
||||
//
|
||||
// tpl should be a string template.
|
||||
func Render(out io.Writer, tpl string, vals interface{}) error {
|
||||
t, err := template.New("helmTpl").Funcs(sprig.TxtFuncMap()).Parse(tpl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debug("Vals: %#v", vals)
|
||||
|
||||
if err := t.ExecuteTemplate(out, "helmTpl", vals); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRender(t *testing.T) {
|
||||
var b bytes.Buffer
|
||||
|
||||
tpl := `{{.Hello | upper}}`
|
||||
vals := map[string]string{"Hello": "hello"}
|
||||
|
||||
if err := Render(&b, tpl, vals); err != nil {
|
||||
t.Errorf("Failed to compile/render template: %s", err)
|
||||
}
|
||||
|
||||
if b.String() != "HELLO" {
|
||||
t.Errorf("Expected HELLO. Got %q", b.String())
|
||||
}
|
||||
}
|
Loading…
Reference in new issue