Reuse strict parameter, when rendering during lint

We want to see the rendering fail, if we missed a value, so we reuse
"--strict".

See #2495,#2036
pull/2972/head
Julian Strobl 8 years ago
parent 76b0d0d8a9
commit bb4c16fcf0

@ -96,7 +96,7 @@ func (l *lintCmd) run() error {
var total int
var failures int
for _, path := range l.paths {
if linter, err := lintChart(path, rvals, l.namespace); err != nil {
if linter, err := lintChart(path, rvals, l.namespace, l.strict); err != nil {
fmt.Println("==> Skipping", path)
fmt.Println(err)
} else {
@ -128,7 +128,7 @@ func (l *lintCmd) run() error {
return nil
}
func lintChart(path string, vals []byte, namespace string) (support.Linter, error) {
func lintChart(path string, vals []byte, namespace string, strict bool) (support.Linter, error) {
var chartPath string
linter := support.Linter{}
@ -160,7 +160,7 @@ func lintChart(path string, vals []byte, namespace string) (support.Linter, erro
return linter, errLintNoChart
}
return lint.All(chartPath, vals, namespace), nil
return lint.All(chartPath, vals, namespace, strict), nil
}
func (l *lintCmd) vals() ([]byte, error) {

@ -23,16 +23,17 @@ import (
var (
values = []byte{}
namespace = "testNamespace"
strict = false
archivedChartPath = "testdata/testcharts/compressedchart-0.1.0.tgz"
chartDirPath = "testdata/testcharts/decompressedchart/"
)
func TestLintChart(t *testing.T) {
if _, err := lintChart(chartDirPath, values, namespace); err != nil {
if _, err := lintChart(chartDirPath, values, namespace, strict); err != nil {
t.Errorf("%s", err)
}
if _, err := lintChart(archivedChartPath, values, namespace); err != nil {
if _, err := lintChart(archivedChartPath, values, namespace, strict); err != nil {
t.Errorf("%s", err)
}

@ -24,13 +24,13 @@ import (
)
// All runs all of the available linters on the given base directory.
func All(basedir string, values []byte, namespace string) support.Linter {
func All(basedir string, values []byte, namespace string, strict bool) support.Linter {
// Using abs path to get directory context
chartDir, _ := filepath.Abs(basedir)
linter := support.Linter{ChartDir: chartDir}
rules.Chartfile(&linter)
rules.Values(&linter)
rules.Templates(&linter, values, namespace)
rules.Templates(&linter, values, namespace, strict)
return linter
}

@ -27,6 +27,7 @@ import (
var values = []byte{}
const namespace = "testNamespace"
const strict = false
const badChartDir = "rules/testdata/badchartfile"
const badValuesFileDir = "rules/testdata/badvaluesfile"
@ -34,7 +35,7 @@ const badYamlFileDir = "rules/testdata/albatross"
const goodChartDir = "rules/testdata/goodone"
func TestBadChart(t *testing.T) {
m := All(badChartDir, values, namespace).Messages
m := All(badChartDir, values, namespace, strict).Messages
if len(m) != 5 {
t.Errorf("Number of errors %v", len(m))
t.Errorf("All didn't fail with expected errors, got %#v", m)
@ -70,7 +71,7 @@ func TestBadChart(t *testing.T) {
}
func TestInvalidYaml(t *testing.T) {
m := All(badYamlFileDir, values, namespace).Messages
m := All(badYamlFileDir, values, namespace, strict).Messages
if len(m) != 1 {
t.Fatalf("All didn't fail with expected errors, got %#v", m)
}
@ -80,7 +81,7 @@ func TestInvalidYaml(t *testing.T) {
}
func TestBadValues(t *testing.T) {
m := All(badValuesFileDir, values, namespace).Messages
m := All(badValuesFileDir, values, namespace, strict).Messages
if len(m) != 1 {
t.Fatalf("All didn't fail with expected errors, got %#v", m)
}
@ -90,7 +91,7 @@ func TestBadValues(t *testing.T) {
}
func TestGoodChart(t *testing.T) {
m := All(goodChartDir, values, namespace).Messages
m := All(goodChartDir, values, namespace, strict).Messages
if len(m) != 0 {
t.Errorf("All failed but shouldn't have: %#v", m)
}

@ -32,7 +32,7 @@ import (
)
// Templates lints the templates in the Linter.
func Templates(linter *support.Linter, values []byte, namespace string) {
func Templates(linter *support.Linter, values []byte, namespace string, strict bool) {
path := "templates/"
templatesPath := filepath.Join(linter.ChartDir, path)
@ -75,7 +75,11 @@ func Templates(linter *support.Linter, values []byte, namespace string) {
//linter.RunLinterRule(support.ErrorSev, err)
return
}
renderedContentMap, err := engine.New().Render(chart, valuesToRender)
e := engine.New()
if strict {
e.Strict = true
}
renderedContentMap, err := e.Render(chart, valuesToRender)
renderOk := linter.RunLinterRule(support.ErrorSev, path, err)

@ -47,10 +47,11 @@ func TestValidateAllowedExtension(t *testing.T) {
var values = []byte("nameOverride: ''\nhttpPort: 80")
const namespace = "testNamespace"
const strict = false
func TestTemplateParsing(t *testing.T) {
linter := support.Linter{ChartDir: templateTestBasedir}
Templates(&linter, values, namespace)
Templates(&linter, values, namespace, strict)
res := linter.Messages
if len(res) != 1 {
@ -73,7 +74,7 @@ func TestTemplateIntegrationHappyPath(t *testing.T) {
defer os.Rename(ignoredTemplatePath, wrongTemplatePath)
linter := support.Linter{ChartDir: templateTestBasedir}
Templates(&linter, values, namespace)
Templates(&linter, values, namespace, strict)
res := linter.Messages
if len(res) != 0 {

Loading…
Cancel
Save