Commit e36647d1 authored by Matt Butcher's avatar Matt Butcher Committed by GitHub

Merge pull request #811 from mouserage/master

Templates partials
parents ff90db6c 66d04cbb
......@@ -5,8 +5,10 @@ import (
"errors"
"fmt"
"log"
"path"
"regexp"
"sort"
"strings"
"github.com/technosophos/moniker"
ctx "golang.org/x/net/context"
......@@ -233,6 +235,11 @@ func (s *releaseServer) InstallRelease(c ctx.Context, req *services.InstallRelea
b := bytes.NewBuffer(nil)
for name, file := range files {
// Ignore templates that starts with underscore to handle them as partials
if strings.HasPrefix(path.Base(name), "_") {
continue
}
// Ignore empty documents because the Kubernetes library can't handle
// them.
if len(file) > 0 {
......
......@@ -97,6 +97,8 @@ func TestInstallReleaseDryRun(t *testing.T) {
{Name: "hello", Data: []byte("hello: world")},
{Name: "goodbye", Data: []byte("goodbye: world")},
{Name: "empty", Data: []byte("")},
{Name: "with-partials", Data: []byte("hello: {{ template \"partials/_planet\" . }}")},
{Name: "partials/_planet", Data: []byte("Earth")},
},
},
DryRun: true,
......@@ -117,6 +119,14 @@ func TestInstallReleaseDryRun(t *testing.T) {
t.Errorf("unexpected output: %s", res.Release.Manifest)
}
if !strings.Contains(res.Release.Manifest, "hello: Earth") {
t.Errorf("Should contain partial content. %s", res.Release.Manifest)
}
if strings.Contains(res.Release.Manifest, "hello: {{ template \"partials/_planet\" . }}") {
t.Errorf("Should not contain partial templates itself. %s", res.Release.Manifest)
}
if strings.Contains(res.Release.Manifest, "empty") {
t.Errorf("Should not contain template data for an empty file. %s", res.Release.Manifest)
}
......
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