fix: removed strict template errors in linter (#8017)

Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
pull/8142/head
Matt Butcher 5 years ago committed by GitHub
parent 524150c662
commit 08e546f169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -81,7 +81,6 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
return
}
var e engine.Engine
e.Strict = strict
e.LintMode = true
renderedContentMap, err := e.Render(chart, valuesToRender)

@ -174,3 +174,55 @@ func TestDeprecatedAPIFails(t *testing.T) {
t.Errorf("Surprised to learn that %q is deprecated", err.Deprecated)
}
}
const manifest = `apiVersion: v1
kind: ConfigMap
metadata:
name: foo
data:
myval1: {{default "val" .Values.mymap.key1 }}
myval2: {{default "val" .Values.mymap.key2 }}
`
// TestSTrictTemplatePrasingMapError is a regression test.
//
// The template engine should not produce an error when a map in values.yaml does
// not contain all possible keys.
//
// See https://github.com/helm/helm/issues/7483
func TestStrictTemplateParsingMapError(t *testing.T) {
ch := chart.Chart{
Metadata: &chart.Metadata{
Name: "regression7483",
APIVersion: "v2",
Version: "0.1.0",
},
Values: map[string]interface{}{
"mymap": map[string]string{
"key1": "val1",
},
},
Templates: []*chart.File{
{
Name: "templates/configmap.yaml",
Data: []byte(manifest),
},
},
}
dir := ensure.TempDir(t)
defer os.RemoveAll(dir)
if err := chartutil.SaveDir(&ch, dir); err != nil {
t.Fatal(err)
}
linter := &support.Linter{
ChartDir: filepath.Join(dir, ch.Metadata.Name),
}
Templates(linter, ch.Values, namespace, strict)
if len(linter.Messages) != 0 {
t.Errorf("expected zero messages, got %d", len(linter.Messages))
for i, msg := range linter.Messages {
t.Logf("Message %d: %q", i, msg)
}
}
}

Loading…
Cancel
Save