diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index c19caab58..77b25140d 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -66,10 +66,7 @@ func (e *Engine) Render(chrt *chart.Chart, vals *chart.Config) (map[string]strin } // Render the charts - tmap := make(map[string]string, len(chrt.Templates)) - for _, tpl := range chrt.Templates { - tmap[tpl.Name] = string(tpl.Data) - } + tmap := allTemplates(chrt) return e.render(tmap, cvals) } @@ -103,3 +100,17 @@ func (e *Engine) render(tpls map[string]string, v interface{}) (map[string]strin return rendered, nil } + +// allTemplates returns all templates for a chart and its dependencies. +func allTemplates(c *chart.Chart) map[string]string { + templates := map[string]string{} + for _, child := range c.Dependencies { + for _, t := range child.Templates { + templates[t.Name] = string(t.Data) + } + } + for _, t := range c.Templates { + templates[t.Name] = string(t.Data) + } + return templates +} diff --git a/pkg/engine/engine_test.go b/pkg/engine/engine_test.go index dba3b2fe3..006a91bcd 100644 --- a/pkg/engine/engine_test.go +++ b/pkg/engine/engine_test.go @@ -4,6 +4,8 @@ import ( "fmt" "sync" "testing" + + "github.com/deis/tiller/pkg/proto/hapi/chart" ) func TestEngine(t *testing.T) { @@ -80,3 +82,55 @@ func TestParallelRenderInternals(t *testing.T) { } wg.Wait() } + +func TestAllTemplates(t *testing.T) { + ch1 := &chart.Chart{ + Templates: []*chart.Template{ + {Name: "foo", Data: []byte("foo")}, + {Name: "bar", Data: []byte("bar")}, + }, + Dependencies: []*chart.Chart{ + {Templates: []*chart.Template{ + {Name: "pinky", Data: []byte("pinky")}, + {Name: "brain", Data: []byte("brain")}, + }}, + }, + } + + tpls := allTemplates(ch1) + if len(tpls) != 4 { + t.Errorf("Expected 4 charts, got %d", len(tpls)) + } +} + +func TestRenderDependency(t *testing.T) { + e := New() + deptpl := `{{define "myblock"}}World{{end}}` + toptpl := `Hello {{template "myblock"}}` + ch := &chart.Chart{ + Templates: []*chart.Template{ + {Name: "outer", Data: []byte(toptpl)}, + }, + Dependencies: []*chart.Chart{ + {Templates: []*chart.Template{ + {Name: "inner", Data: []byte(deptpl)}, + }}, + }, + } + + out, err := e.Render(ch, nil) + + if err != nil { + t.Fatalf("failed to render chart: %s", err) + } + + if len(out) != 2 { + t.Errorf("Expected 2, got %d", len(out)) + } + + expect := "Hello World" + if out["outer"] != expect { + t.Errorf("Expected %q, got %q", expect, out["outer"]) + } + +}