Skip to content

Commit

Permalink
revert the removal of strict param in functions for better backwards …
Browse files Browse the repository at this point in the history
…compatibility

Signed-off-by: Jeff Knurek <knurek.stuff@gmail.com>
  • Loading branch information
jeff-knurek committed Aug 7, 2020
1 parent a979ba8 commit cd90fb4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions cmd/helm/lint.go
Expand Up @@ -97,7 +97,7 @@ func (l *lintCmd) run() error {
var total int
var failures int
for _, path := range l.paths {
linter, err := lintChart(path, rvals, l.namespace)
linter, err := lintChart(path, rvals, l.namespace, l.strict)
if err != nil {
failures = failures + 1
fmt.Println("==> Skipping", path)
Expand Down Expand Up @@ -132,7 +132,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{}

Expand Down Expand Up @@ -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 lint.All(chartPath, vals, namespace), nil
return lint.All(chartPath, vals, namespace, strict), nil
}

// vals merges values from files specified via -f/--values and
Expand Down
3 changes: 2 additions & 1 deletion cmd/helm/lint_test.go
Expand Up @@ -58,10 +58,11 @@ func TestLintChart(t *testing.T) {

values := []byte{}
namespace := "testNamespace"
strict := false

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := lintChart(tt.chartPath, values, namespace)
_, err := lintChart(tt.chartPath, values, namespace, strict)
switch {
case err != nil && !tt.err:
t.Errorf("%s", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/lint/lint.go
Expand Up @@ -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
}
11 changes: 6 additions & 5 deletions pkg/lint/lint_test.go
Expand Up @@ -31,14 +31,15 @@ var values = []byte{}

const (
namespace = "testNamespace"
strict = false
badChartDir = "rules/testdata/badchartfile"
badValuesFileDir = "rules/testdata/badvaluesfile"
badYamlFileDir = "rules/testdata/albatross"
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) != 6 {
t.Errorf("Number of errors %v", len(m))
t.Errorf("All didn't fail with expected errors, got %#v", m)
Expand Down Expand Up @@ -78,7 +79,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)
}
Expand All @@ -88,7 +89,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)
}
Expand All @@ -98,7 +99,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)
}
Expand Down Expand Up @@ -129,7 +130,7 @@ func TestHelmCreateChart(t *testing.T) {
return
}

m := All(createdChart, values, namespace).Messages
m := All(createdChart, values, namespace, strict).Messages
if ll := len(m); ll != 1 {
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") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/lint/rules/template.go
Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions pkg/lint/rules/template_test.go
Expand Up @@ -55,7 +55,7 @@ var values = []byte("nameOverride: ''\nhttpPort: 80")

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 {
Expand All @@ -78,7 +78,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 {
Expand Down Expand Up @@ -112,6 +112,7 @@ data:
myval1: {{default "val" .Values.mymap.key1 }}
myval2: {{default "val" .Values.mymap.key2 }}
`
var ingoredStrict = true
ch := chart.Chart{
Metadata: &chart.Metadata{
Name: "regression.6705",
Expand All @@ -132,7 +133,7 @@ data:
linter := &support.Linter{
ChartDir: filepath.Join(dir, ch.Metadata.Name),
}
Templates(linter, vals, namespace)
Templates(linter, vals, namespace, ingoredStrict)
if len(linter.Messages) != 0 {
t.Errorf("expected zero messages, got %d", len(linter.Messages))
for i, msg := range linter.Messages {
Expand Down

0 comments on commit cd90fb4

Please sign in to comment.