Commit 07312c68 authored by Matt Butcher's avatar Matt Butcher

fix(engine): support chart template recursion

parent 60779683
......@@ -104,13 +104,16 @@ func (e *Engine) render(tpls map[string]string, v interface{}) (map[string]strin
// allTemplates returns all templates for a chart and its dependencies.
func allTemplates(c *chart.Chart) map[string]string {
templates := map[string]string{}
recAllTpls(c, templates)
return templates
}
func recAllTpls(c *chart.Chart, templates map[string]string) {
for _, child := range c.Dependencies {
for _, t := range child.Templates {
templates[t.Name] = string(t.Data)
}
recAllTpls(child, templates)
}
for _, t := range c.Templates {
templates[t.Name] = string(t.Data)
}
return templates
}
......@@ -90,16 +90,23 @@ func TestAllTemplates(t *testing.T) {
{Name: "bar", Data: []byte("bar")},
},
Dependencies: []*chart.Chart{
{Templates: []*chart.Template{
{Name: "pinky", Data: []byte("pinky")},
{Name: "brain", Data: []byte("brain")},
}},
{
Templates: []*chart.Template{
{Name: "pinky", Data: []byte("pinky")},
{Name: "brain", Data: []byte("brain")},
},
Dependencies: []*chart.Chart{
{Templates: []*chart.Template{
{Name: "innermost", Data: []byte("innermost")},
}},
},
},
},
}
tpls := allTemplates(ch1)
if len(tpls) != 4 {
t.Errorf("Expected 4 charts, got %d", len(tpls))
if len(tpls) != 5 {
t.Errorf("Expected 5 charts, got %d", len(tpls))
}
}
......@@ -112,9 +119,11 @@ func TestRenderDependency(t *testing.T) {
{Name: "outer", Data: []byte(toptpl)},
},
Dependencies: []*chart.Chart{
{Templates: []*chart.Template{
{Name: "inner", Data: []byte(deptpl)},
}},
{
Templates: []*chart.Template{
{Name: "inner", Data: []byte(deptpl)},
},
},
},
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment