From 68a8f36a9288b918767bd21d107cac3ccfda22c0 Mon Sep 17 00:00:00 2001 From: Vibhav Bobade Date: Mon, 19 Aug 2019 03:58:48 +0530 Subject: [PATCH] Fix Adding Errors from Linter.Messages to result.Errors This also fixes beig added to result.Errors Signed-off-by: Vibhav Bobade --- pkg/action/lint.go | 13 ++++++++++--- pkg/action/lint_test.go | 9 ++++++++- pkg/lint/rules/template.go | 4 +--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/action/lint.go b/pkg/action/lint.go index 6a0ec1488..f9c0c613f 100644 --- a/pkg/action/lint.go +++ b/pkg/action/lint.go @@ -59,15 +59,22 @@ func (l *Lint) Run(paths []string, vals map[string]interface{}) *LintResult { result := &LintResult{} for _, path := range paths { - if linter, err := lintChart(path, vals, l.Namespace, l.Strict); err != nil { + linter, err := lintChart(path, vals, l.Namespace, l.Strict) + if err != nil { if err == errLintNoChart { result.Errors = append(result.Errors, err) } + if linter.HighestSeverity >= lowestTolerance { + result.Errors = append(result.Errors, err) + } } else { result.Messages = append(result.Messages, linter.Messages...) result.TotalChartsLinted++ - if linter.HighestSeverity >= lowestTolerance { - result.Errors = append(result.Errors, err) + for _, msg := range linter.Messages { + if msg.Severity == support.ErrorSev { + result.Errors = append(result.Errors, msg.Err) + result.Messages = append(result.Messages, msg) + } } } } diff --git a/pkg/action/lint_test.go b/pkg/action/lint_test.go index 45af0df95..7f7765af5 100644 --- a/pkg/action/lint_test.go +++ b/pkg/action/lint_test.go @@ -62,8 +62,15 @@ func TestLintChart(t *testing.T) { func TestLint_MultipleCharts(t *testing.T) { testCharts := []string{chart2MultipleChartLint, chart1MultipleChartLint} testLint := NewLint() - if result := testLint.Run(testCharts, values); len(result.Errors) == 0 { + if result := testLint.Run(testCharts, values); len(result.Errors) > 0 { t.Error(result.Errors) } +} +func TestLint_EmptyResultErrors(t *testing.T) { + testCharts := []string{chart2MultipleChartLint} + testLint := NewLint() + if result := testLint.Run(testCharts, values); len(result.Errors) > 0 { + t.Error("Expected no error, got more") + } } diff --git a/pkg/lint/rules/template.go b/pkg/lint/rules/template.go index db86417dc..36230c4ee 100644 --- a/pkg/lint/rules/template.go +++ b/pkg/lint/rules/template.go @@ -61,9 +61,7 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace } valuesToRender, err := chartutil.ToRenderValues(chart, cvals, options, nil) if err != nil { - // FIXME: This seems to generate a duplicate, but I can't find where the first - // error is coming from. - //linter.RunLinterRule(support.ErrorSev, err) + linter.RunLinterRule(support.ErrorSev, path, err) return } var e engine.Engine