revert the removal of strict param in functions for better backwards compatibility

Signed-off-by: Jeff Knurek <knurek.stuff@gmail.com>
pull/8516/head
Jeff Knurek 4 years ago
parent a979ba8c58
commit cd90fb4319

@ -97,7 +97,7 @@ func (l *lintCmd) run() error {
var total int var total int
var failures int var failures int
for _, path := range l.paths { for _, path := range l.paths {
linter, err := lintChart(path, rvals, l.namespace) linter, err := lintChart(path, rvals, l.namespace, l.strict)
if err != nil { if err != nil {
failures = failures + 1 failures = failures + 1
fmt.Println("==> Skipping", path) fmt.Println("==> Skipping", path)
@ -132,7 +132,7 @@ func (l *lintCmd) run() error {
return nil 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 var chartPath string
linter := support.Linter{} linter := support.Linter{}
@ -171,7 +171,7 @@ func lintChart(path string, vals []byte, namespace string) (support.Linter, erro
return linter, fmt.Errorf("unable to check Chart.yaml file in chart: %s", err.Error()) return linter, fmt.Errorf("unable to check Chart.yaml file in chart: %s", err.Error())
} }
return lint.All(chartPath, vals, namespace), nil return lint.All(chartPath, vals, namespace, strict), nil
} }
// vals merges values from files specified via -f/--values and // vals merges values from files specified via -f/--values and

@ -58,10 +58,11 @@ func TestLintChart(t *testing.T) {
values := []byte{} values := []byte{}
namespace := "testNamespace" namespace := "testNamespace"
strict := false
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
_, err := lintChart(tt.chartPath, values, namespace) _, err := lintChart(tt.chartPath, values, namespace, strict)
switch { switch {
case err != nil && !tt.err: case err != nil && !tt.err:
t.Errorf("%s", err) t.Errorf("%s", err)

@ -24,13 +24,13 @@ import (
) )
// All runs all of the available linters on the given base directory. // 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 // Using abs path to get directory context
chartDir, _ := filepath.Abs(basedir) chartDir, _ := filepath.Abs(basedir)
linter := support.Linter{ChartDir: chartDir} linter := support.Linter{ChartDir: chartDir}
rules.Chartfile(&linter) rules.Chartfile(&linter)
rules.Values(&linter) rules.Values(&linter)
rules.Templates(&linter, values, namespace) rules.Templates(&linter, values, namespace, strict)
return linter return linter
} }

@ -31,6 +31,7 @@ var values = []byte{}
const ( const (
namespace = "testNamespace" namespace = "testNamespace"
strict = false
badChartDir = "rules/testdata/badchartfile" badChartDir = "rules/testdata/badchartfile"
badValuesFileDir = "rules/testdata/badvaluesfile" badValuesFileDir = "rules/testdata/badvaluesfile"
badYamlFileDir = "rules/testdata/albatross" badYamlFileDir = "rules/testdata/albatross"
@ -38,7 +39,7 @@ const (
) )
func TestBadChart(t *testing.T) { func TestBadChart(t *testing.T) {
m := All(badChartDir, values, namespace).Messages m := All(badChartDir, values, namespace, strict).Messages
if len(m) != 6 { if len(m) != 6 {
t.Errorf("Number of errors %v", len(m)) t.Errorf("Number of errors %v", len(m))
t.Errorf("All didn't fail with expected errors, got %#v", m) t.Errorf("All didn't fail with expected errors, got %#v", m)
@ -78,7 +79,7 @@ func TestBadChart(t *testing.T) {
} }
func TestInvalidYaml(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 { if len(m) != 1 {
t.Fatalf("All didn't fail with expected errors, got %#v", m) t.Fatalf("All didn't fail with expected errors, got %#v", m)
} }
@ -88,7 +89,7 @@ func TestInvalidYaml(t *testing.T) {
} }
func TestBadValues(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 { if len(m) != 1 {
t.Fatalf("All didn't fail with expected errors, got %#v", m) t.Fatalf("All didn't fail with expected errors, got %#v", m)
} }
@ -98,7 +99,7 @@ func TestBadValues(t *testing.T) {
} }
func TestGoodChart(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 { if len(m) != 0 {
t.Errorf("All failed but shouldn't have: %#v", m) t.Errorf("All failed but shouldn't have: %#v", m)
} }
@ -129,7 +130,7 @@ func TestHelmCreateChart(t *testing.T) {
return return
} }
m := All(createdChart, values, namespace).Messages m := All(createdChart, values, namespace, strict).Messages
if ll := len(m); ll != 1 { if ll := len(m); ll != 1 {
t.Errorf("All should have had exactly 1 error. Got %d", ll) t.Errorf("All should have had exactly 1 error. Got %d", ll)
} else if msg := m[0].Err.Error(); !strings.Contains(msg, "icon is recommended") { } else if msg := m[0].Err.Error(); !strings.Contains(msg, "icon is recommended") {

@ -32,7 +32,7 @@ import (
) )
// Templates lints the templates in the Linter. // 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/" path := "templates/"
templatesPath := filepath.Join(linter.ChartDir, path) templatesPath := filepath.Join(linter.ChartDir, path)

@ -55,7 +55,7 @@ var values = []byte("nameOverride: ''\nhttpPort: 80")
func TestTemplateParsing(t *testing.T) { func TestTemplateParsing(t *testing.T) {
linter := support.Linter{ChartDir: templateTestBasedir} linter := support.Linter{ChartDir: templateTestBasedir}
Templates(&linter, values, namespace) Templates(&linter, values, namespace, strict)
res := linter.Messages res := linter.Messages
if len(res) != 1 { if len(res) != 1 {
@ -78,7 +78,7 @@ func TestTemplateIntegrationHappyPath(t *testing.T) {
defer os.Rename(ignoredTemplatePath, wrongTemplatePath) defer os.Rename(ignoredTemplatePath, wrongTemplatePath)
linter := support.Linter{ChartDir: templateTestBasedir} linter := support.Linter{ChartDir: templateTestBasedir}
Templates(&linter, values, namespace) Templates(&linter, values, namespace, strict)
res := linter.Messages res := linter.Messages
if len(res) != 0 { if len(res) != 0 {
@ -112,6 +112,7 @@ data:
myval1: {{default "val" .Values.mymap.key1 }} myval1: {{default "val" .Values.mymap.key1 }}
myval2: {{default "val" .Values.mymap.key2 }} myval2: {{default "val" .Values.mymap.key2 }}
` `
var ingoredStrict = true
ch := chart.Chart{ ch := chart.Chart{
Metadata: &chart.Metadata{ Metadata: &chart.Metadata{
Name: "regression.6705", Name: "regression.6705",
@ -132,7 +133,7 @@ data:
linter := &support.Linter{ linter := &support.Linter{
ChartDir: filepath.Join(dir, ch.Metadata.Name), ChartDir: filepath.Join(dir, ch.Metadata.Name),
} }
Templates(linter, vals, namespace) Templates(linter, vals, namespace, ingoredStrict)
if len(linter.Messages) != 0 { if len(linter.Messages) != 0 {
t.Errorf("expected zero messages, got %d", len(linter.Messages)) t.Errorf("expected zero messages, got %d", len(linter.Messages))
for i, msg := range linter.Messages { for i, msg := range linter.Messages {

Loading…
Cancel
Save